})
})
expect(dummy).toBe(1)
- ;(map.get(1) as any).foo++
+ map.get(1)!.foo++
expect(dummy).toBe(2)
})
}
})
expect(dummy).toBe(1)
- ;(map.get(1) as any).foo++
+ map.get(1)!.foo++
expect(dummy).toBe(2)
})
}
})
expect(dummy).toBe(1)
- ;(map.get(key) as any).foo++
+ map.get(key)!.foo++
expect(dummy).toBe(2)
})
}
})
expect(dummy).toBe(1)
- ;(map.get(key) as any).foo++
+ map.get(key)!.foo++
expect(dummy).toBe(2)
})
})
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
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()) {
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
})
it('should compute lazily', () => {
- const value: any = reactive({})
+ const value = reactive<{ foo?: number }>({})
const getter = jest.fn(() => value.foo)
const cValue = computed(getter)
})
it('should trigger effect', () => {
- const value: any = reactive({})
+ const value = reactive<{ foo?: number }>({})
const cValue = computed(() => value.foo)
let dummy
effect(() => {
})
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)
})
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
})
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
})
it('should no longer update when stopped', () => {
- const value: any = reactive({})
+ const value = reactive<{ foo?: number }>({})
const cValue = computed(() => value.foo)
let dummy
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)
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
it('should observe sparse array mutations', () => {
let dummy
- const list: any[] = reactive([])
+ const list = reactive<string[]>([])
list[1] = 'World!'
effect(() => (dummy = list.join(' ')))
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) {
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)
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)
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
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]
})
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)
})
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)
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)