chore: improve typings in reactivity tests (#96)

This commit is contained in:
Carlos Rodrigues 2019-10-05 15:39:40 +01:00 committed by Evan You
parent 0fe8801782
commit 600ec5de42
6 changed files with 24 additions and 24 deletions

View File

@ -247,7 +247,7 @@ describe('reactivity/collections', () => {
}) })
}) })
expect(dummy).toBe(1) expect(dummy).toBe(1)
;(map.get(1) as any).foo++ map.get(1)!.foo++
expect(dummy).toBe(2) expect(dummy).toBe(2)
}) })
@ -262,7 +262,7 @@ describe('reactivity/collections', () => {
} }
}) })
expect(dummy).toBe(1) expect(dummy).toBe(1)
;(map.get(1) as any).foo++ map.get(1)!.foo++
expect(dummy).toBe(2) expect(dummy).toBe(2)
}) })
@ -280,7 +280,7 @@ describe('reactivity/collections', () => {
} }
}) })
expect(dummy).toBe(1) expect(dummy).toBe(1)
;(map.get(key) as any).foo++ map.get(key)!.foo++
expect(dummy).toBe(2) expect(dummy).toBe(2)
}) })
@ -298,7 +298,7 @@ describe('reactivity/collections', () => {
} }
}) })
expect(dummy).toBe(1) expect(dummy).toBe(1)
;(map.get(key) as any).foo++ map.get(key)!.foo++
expect(dummy).toBe(2) expect(dummy).toBe(2)
}) })
}) })

View File

@ -102,7 +102,7 @@ describe('reactivity/collections', () => {
it('should observe entries iteration', () => { it('should observe entries iteration', () => {
let dummy let dummy
const set = reactive(new Set() as Set<number>) const set = reactive(new Set<number>())
effect(() => { effect(() => {
dummy = 0 dummy = 0
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
@ -196,7 +196,7 @@ describe('reactivity/collections', () => {
it('should not observe raw iterations', () => { it('should not observe raw iterations', () => {
let dummy = 0 let dummy = 0
const set = reactive(new Set() as Set<number>) const set = reactive(new Set<number>())
effect(() => { effect(() => {
dummy = 0 dummy = 0
for (let [num] of toRaw(set).entries()) { for (let [num] of toRaw(set).entries()) {

View File

@ -2,7 +2,7 @@ import { computed, reactive, effect, stop, ref } from '../src'
describe('reactivity/computed', () => { describe('reactivity/computed', () => {
it('should return updated value', () => { it('should return updated value', () => {
const value: any = reactive({}) const value = reactive<{ foo?: number }>({})
const cValue = computed(() => value.foo) const cValue = computed(() => value.foo)
expect(cValue.value).toBe(undefined) expect(cValue.value).toBe(undefined)
value.foo = 1 value.foo = 1
@ -10,7 +10,7 @@ describe('reactivity/computed', () => {
}) })
it('should compute lazily', () => { it('should compute lazily', () => {
const value: any = reactive({}) const value = reactive<{ foo?: number }>({})
const getter = jest.fn(() => value.foo) const getter = jest.fn(() => value.foo)
const cValue = computed(getter) const cValue = computed(getter)
@ -38,7 +38,7 @@ describe('reactivity/computed', () => {
}) })
it('should trigger effect', () => { it('should trigger effect', () => {
const value: any = reactive({}) const value = reactive<{ foo?: number }>({})
const cValue = computed(() => value.foo) const cValue = computed(() => value.foo)
let dummy let dummy
effect(() => { effect(() => {
@ -50,7 +50,7 @@ describe('reactivity/computed', () => {
}) })
it('should work when chained', () => { it('should work when chained', () => {
const value: any = reactive({ foo: 0 }) const value = reactive({ foo: 0 })
const c1 = computed(() => value.foo) const c1 = computed(() => value.foo)
const c2 = computed(() => c1.value + 1) const c2 = computed(() => c1.value + 1)
expect(c2.value).toBe(1) expect(c2.value).toBe(1)
@ -61,7 +61,7 @@ describe('reactivity/computed', () => {
}) })
it('should trigger effect when chained', () => { it('should trigger effect when chained', () => {
const value: any = reactive({ foo: 0 }) const value = reactive({ foo: 0 })
const getter1 = jest.fn(() => value.foo) const getter1 = jest.fn(() => value.foo)
const getter2 = jest.fn(() => { const getter2 = jest.fn(() => {
return c1.value + 1 return c1.value + 1
@ -84,7 +84,7 @@ describe('reactivity/computed', () => {
}) })
it('should trigger effect when chained (mixed invocations)', () => { 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 getter1 = jest.fn(() => value.foo)
const getter2 = jest.fn(() => { const getter2 = jest.fn(() => {
return c1.value + 1 return c1.value + 1
@ -108,7 +108,7 @@ describe('reactivity/computed', () => {
}) })
it('should no longer update when stopped', () => { it('should no longer update when stopped', () => {
const value: any = reactive({}) const value = reactive<{ foo?: number }>({})
const cValue = computed(() => value.foo) const cValue = computed(() => value.foo)
let dummy let dummy
effect(() => { effect(() => {

View File

@ -71,7 +71,7 @@ describe('reactivity/effect', () => {
it('should observe has operations', () => { it('should observe has operations', () => {
let dummy let dummy
const obj: any = reactive({ prop: 'value' }) const obj = reactive<{ prop: string | number }>({ prop: 'value' })
effect(() => (dummy = 'prop' in obj)) effect(() => (dummy = 'prop' in obj))
expect(dummy).toBe(true) expect(dummy).toBe(true)
@ -115,7 +115,7 @@ describe('reactivity/effect', () => {
it('should observe inherited property accessors', () => { it('should observe inherited property accessors', () => {
let dummy, parentDummy, hiddenValue: any let dummy, parentDummy, hiddenValue: any
const obj: any = reactive({}) const obj = reactive<{ prop?: number }>({})
const parent = reactive({ const parent = reactive({
set prop(value) { set prop(value) {
hiddenValue = value hiddenValue = value
@ -179,7 +179,7 @@ describe('reactivity/effect', () => {
it('should observe sparse array mutations', () => { it('should observe sparse array mutations', () => {
let dummy let dummy
const list: any[] = reactive([]) const list = reactive<string[]>([])
list[1] = 'World!' list[1] = 'World!'
effect(() => (dummy = list.join(' '))) effect(() => (dummy = list.join(' ')))
@ -192,7 +192,7 @@ describe('reactivity/effect', () => {
it('should observe enumeration', () => { it('should observe enumeration', () => {
let dummy = 0 let dummy = 0
const numbers: any = reactive({ num1: 3 }) const numbers = reactive<Record<string, number>>({ num1: 3 })
effect(() => { effect(() => {
dummy = 0 dummy = 0
for (let key in numbers) { for (let key in numbers) {
@ -269,7 +269,7 @@ describe('reactivity/effect', () => {
it('should not observe raw mutations', () => { it('should not observe raw mutations', () => {
let dummy let dummy
const obj: any = reactive({}) const obj = reactive<{ prop?: string }>({})
effect(() => (dummy = toRaw(obj).prop)) effect(() => (dummy = toRaw(obj).prop))
expect(dummy).toBe(undefined) expect(dummy).toBe(undefined)
@ -279,7 +279,7 @@ describe('reactivity/effect', () => {
it('should not be triggered by raw mutations', () => { it('should not be triggered by raw mutations', () => {
let dummy let dummy
const obj: any = reactive({}) const obj = reactive<{ prop?: string }>({})
effect(() => (dummy = obj.prop)) effect(() => (dummy = obj.prop))
expect(dummy).toBe(undefined) expect(dummy).toBe(undefined)
@ -289,7 +289,7 @@ describe('reactivity/effect', () => {
it('should not be triggered by inherited raw setters', () => { it('should not be triggered by inherited raw setters', () => {
let dummy, parentDummy, hiddenValue: any let dummy, parentDummy, hiddenValue: any
const obj: any = reactive({}) const obj = reactive<{ prop?: number }>({})
const parent = reactive({ const parent = reactive({
set prop(value) { set prop(value) {
hiddenValue = value hiddenValue = value
@ -437,7 +437,7 @@ describe('reactivity/effect', () => {
it('should not run multiple times for a single mutation', () => { it('should not run multiple times for a single mutation', () => {
let dummy let dummy
const obj: any = reactive({}) const obj = reactive<Record<string, number>>({})
const fnSpy = jest.fn(() => { const fnSpy = jest.fn(() => {
for (const key in obj) { for (const key in obj) {
dummy = obj[key] dummy = obj[key]

View File

@ -19,7 +19,7 @@ describe('reactivity/reactive', () => {
}) })
test('Array', () => { test('Array', () => {
const original: any[] = [{ foo: 1 }] const original = [{ foo: 1 }]
const observed = reactive(original) const observed = reactive(original)
expect(observed).not.toBe(original) expect(observed).not.toBe(original)
expect(isReactive(observed)).toBe(true) expect(isReactive(observed)).toBe(true)
@ -88,7 +88,7 @@ describe('reactivity/reactive', () => {
}) })
test('setting a property with an unobserved value should wrap with reactive', () => { test('setting a property with an unobserved value should wrap with reactive', () => {
const observed: any = reactive({}) const observed = reactive<{ foo?: object }>({})
const raw = {} const raw = {}
observed.foo = raw observed.foo = raw
expect(observed.foo).not.toBe(raw) expect(observed.foo).not.toBe(raw)

View File

@ -106,7 +106,7 @@ describe('reactivity/readonly', () => {
describe('Array', () => { describe('Array', () => {
it('should make nested values readonly', () => { it('should make nested values readonly', () => {
const original: any[] = [{ foo: 1 }] const original = [{ foo: 1 }]
const observed = readonly(original) const observed = readonly(original)
expect(observed).not.toBe(original) expect(observed).not.toBe(original)
expect(isReactive(observed)).toBe(true) expect(isReactive(observed)).toBe(true)