]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
chore: improve typings in reactivity tests (#96)
authorCarlos Rodrigues <david-181@hotmail.com>
Sat, 5 Oct 2019 14:39:40 +0000 (15:39 +0100)
committerEvan You <yyx990803@gmail.com>
Sat, 5 Oct 2019 14:39:40 +0000 (10:39 -0400)
packages/reactivity/__tests__/collections/Map.spec.ts
packages/reactivity/__tests__/collections/Set.spec.ts
packages/reactivity/__tests__/computed.spec.ts
packages/reactivity/__tests__/effect.spec.ts
packages/reactivity/__tests__/reactive.spec.ts
packages/reactivity/__tests__/readonly.spec.ts

index bb5f4f6b2a45747870b39428cba27701cec76dd6..984beb3d560a75e303c27e7d4da307d159f4f44b 100644 (file)
@@ -247,7 +247,7 @@ describe('reactivity/collections', () => {
         })
       })
       expect(dummy).toBe(1)
-      ;(map.get(1) as any).foo++
+      map.get(1)!.foo++
       expect(dummy).toBe(2)
     })
 
@@ -262,7 +262,7 @@ describe('reactivity/collections', () => {
         }
       })
       expect(dummy).toBe(1)
-      ;(map.get(1) as any).foo++
+      map.get(1)!.foo++
       expect(dummy).toBe(2)
     })
 
@@ -280,7 +280,7 @@ describe('reactivity/collections', () => {
         }
       })
       expect(dummy).toBe(1)
-      ;(map.get(key) as any).foo++
+      map.get(key)!.foo++
       expect(dummy).toBe(2)
     })
 
@@ -298,7 +298,7 @@ describe('reactivity/collections', () => {
         }
       })
       expect(dummy).toBe(1)
-      ;(map.get(key) as any).foo++
+      map.get(key)!.foo++
       expect(dummy).toBe(2)
     })
   })
index 3efa18250ea5217f1ff34a4807b5489c304265ea..f01090d2f5457e7157927d41196525564945b2be 100644 (file)
@@ -102,7 +102,7 @@ describe('reactivity/collections', () => {
 
     it('should observe entries iteration', () => {
       let dummy
-      const set = reactive(new Set() as Set<number>)
+      const set = reactive(new Set<number>())
       effect(() => {
         dummy = 0
         // eslint-disable-next-line no-unused-vars
@@ -196,7 +196,7 @@ describe('reactivity/collections', () => {
 
     it('should not observe raw iterations', () => {
       let dummy = 0
-      const set = reactive(new Set() as Set<number>)
+      const set = reactive(new Set<number>())
       effect(() => {
         dummy = 0
         for (let [num] of toRaw(set).entries()) {
index 898f9cac20ed4bff35ab84f468426492b6be2dc4..a9199f554c1709736e76a846352241c2c3e7ebbd 100644 (file)
@@ -2,7 +2,7 @@ import { computed, reactive, effect, stop, ref } from '../src'
 
 describe('reactivity/computed', () => {
   it('should return updated value', () => {
-    const value: any = reactive({})
+    const value = reactive<{ foo?: number }>({})
     const cValue = computed(() => value.foo)
     expect(cValue.value).toBe(undefined)
     value.foo = 1
@@ -10,7 +10,7 @@ describe('reactivity/computed', () => {
   })
 
   it('should compute lazily', () => {
-    const value: any = reactive({})
+    const value = reactive<{ foo?: number }>({})
     const getter = jest.fn(() => value.foo)
     const cValue = computed(getter)
 
@@ -38,7 +38,7 @@ describe('reactivity/computed', () => {
   })
 
   it('should trigger effect', () => {
-    const value: any = reactive({})
+    const value = reactive<{ foo?: number }>({})
     const cValue = computed(() => value.foo)
     let dummy
     effect(() => {
@@ -50,7 +50,7 @@ describe('reactivity/computed', () => {
   })
 
   it('should work when chained', () => {
-    const value: any = reactive({ foo: 0 })
+    const value = reactive({ foo: 0 })
     const c1 = computed(() => value.foo)
     const c2 = computed(() => c1.value + 1)
     expect(c2.value).toBe(1)
@@ -61,7 +61,7 @@ describe('reactivity/computed', () => {
   })
 
   it('should trigger effect when chained', () => {
-    const value: any = reactive({ foo: 0 })
+    const value = reactive({ foo: 0 })
     const getter1 = jest.fn(() => value.foo)
     const getter2 = jest.fn(() => {
       return c1.value + 1
@@ -84,7 +84,7 @@ describe('reactivity/computed', () => {
   })
 
   it('should trigger effect when chained (mixed invocations)', () => {
-    const value: any = reactive({ foo: 0 })
+    const value = reactive({ foo: 0 })
     const getter1 = jest.fn(() => value.foo)
     const getter2 = jest.fn(() => {
       return c1.value + 1
@@ -108,7 +108,7 @@ describe('reactivity/computed', () => {
   })
 
   it('should no longer update when stopped', () => {
-    const value: any = reactive({})
+    const value = reactive<{ foo?: number }>({})
     const cValue = computed(() => value.foo)
     let dummy
     effect(() => {
index 758fedeb27f6b2a32f8f842207509946aeb87d6c..9538e5b896bca3f7d74120157f1aef45dfb82e58 100644 (file)
@@ -71,7 +71,7 @@ describe('reactivity/effect', () => {
 
   it('should observe has operations', () => {
     let dummy
-    const obj: any = reactive({ prop: 'value' })
+    const obj = reactive<{ prop: string | number }>({ prop: 'value' })
     effect(() => (dummy = 'prop' in obj))
 
     expect(dummy).toBe(true)
@@ -115,7 +115,7 @@ describe('reactivity/effect', () => {
 
   it('should observe inherited property accessors', () => {
     let dummy, parentDummy, hiddenValue: any
-    const obj: any = reactive({})
+    const obj = reactive<{ prop?: number }>({})
     const parent = reactive({
       set prop(value) {
         hiddenValue = value
@@ -179,7 +179,7 @@ describe('reactivity/effect', () => {
 
   it('should observe sparse array mutations', () => {
     let dummy
-    const list: any[] = reactive([])
+    const list = reactive<string[]>([])
     list[1] = 'World!'
     effect(() => (dummy = list.join(' ')))
 
@@ -192,7 +192,7 @@ describe('reactivity/effect', () => {
 
   it('should observe enumeration', () => {
     let dummy = 0
-    const numbers: any = reactive({ num1: 3 })
+    const numbers = reactive<Record<string, number>>({ num1: 3 })
     effect(() => {
       dummy = 0
       for (let key in numbers) {
@@ -269,7 +269,7 @@ describe('reactivity/effect', () => {
 
   it('should not observe raw mutations', () => {
     let dummy
-    const obj: any = reactive({})
+    const obj = reactive<{ prop?: string }>({})
     effect(() => (dummy = toRaw(obj).prop))
 
     expect(dummy).toBe(undefined)
@@ -279,7 +279,7 @@ describe('reactivity/effect', () => {
 
   it('should not be triggered by raw mutations', () => {
     let dummy
-    const obj: any = reactive({})
+    const obj = reactive<{ prop?: string }>({})
     effect(() => (dummy = obj.prop))
 
     expect(dummy).toBe(undefined)
@@ -289,7 +289,7 @@ describe('reactivity/effect', () => {
 
   it('should not be triggered by inherited raw setters', () => {
     let dummy, parentDummy, hiddenValue: any
-    const obj: any = reactive({})
+    const obj = reactive<{ prop?: number }>({})
     const parent = reactive({
       set prop(value) {
         hiddenValue = value
@@ -437,7 +437,7 @@ describe('reactivity/effect', () => {
 
   it('should not run multiple times for a single mutation', () => {
     let dummy
-    const obj: any = reactive({})
+    const obj = reactive<Record<string, number>>({})
     const fnSpy = jest.fn(() => {
       for (const key in obj) {
         dummy = obj[key]
index 681a960992fdd5f809d98806822e5ed3a1dc6906..ebeac774d56e576b747b76052e9c27590bc1955e 100644 (file)
@@ -19,7 +19,7 @@ describe('reactivity/reactive', () => {
   })
 
   test('Array', () => {
-    const original: any[] = [{ foo: 1 }]
+    const original = [{ foo: 1 }]
     const observed = reactive(original)
     expect(observed).not.toBe(original)
     expect(isReactive(observed)).toBe(true)
@@ -88,7 +88,7 @@ describe('reactivity/reactive', () => {
   })
 
   test('setting a property with an unobserved value should wrap with reactive', () => {
-    const observed: any = reactive({})
+    const observed = reactive<{ foo?: object }>({})
     const raw = {}
     observed.foo = raw
     expect(observed.foo).not.toBe(raw)
index c2dbb3a8cb556654974d2b71da216d464d57d1d9..de59e0b50741b1828f0b3f7c1d48aa187946345d 100644 (file)
@@ -106,7 +106,7 @@ describe('reactivity/readonly', () => {
 
   describe('Array', () => {
     it('should make nested values readonly', () => {
-      const original: any[] = [{ foo: 1 }]
+      const original = [{ foo: 1 }]
       const observed = readonly(original)
       expect(observed).not.toBe(original)
       expect(isReactive(observed)).toBe(true)