Skip to content

Commit c4dfc10

Browse files
authored
test: add test cases for reactivity/set (#744)
Co-authored-by: webfansplz <>
1 parent 9969eee commit c4dfc10

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

test/v3/reactivity/set.spec.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1-
import { set, ref, watchEffect } from '../../../src'
1+
import { set, reactive, ref, watch, watchEffect } from '../../../src'
22

33
describe('reactivity/set', () => {
4+
it('should not trigger reactivity on native object member assignment', () => {
5+
const obj = reactive<{ a?: number }>({})
6+
const spy = jest.fn()
7+
watch(obj, spy, { deep: true, flush: 'sync' })
8+
obj.a = 1
9+
expect(spy).not.toHaveBeenCalled()
10+
expect(obj).toStrictEqual({ a: 1 })
11+
})
12+
13+
it('should trigger reactivity when using set on reactive object', () => {
14+
const obj = reactive<{ a?: number }>({})
15+
const spy = jest.fn()
16+
watch(obj, spy, { deep: true, flush: 'sync' })
17+
set(obj, 'a', 1)
18+
expect(spy).toBeCalledTimes(1)
19+
expect(obj).toStrictEqual({ a: 1 })
20+
})
21+
422
it('should trigger watchEffect when using set to change value of array length', () => {
523
const arr = ref([1, 2, 3])
624
const spy = jest.fn()

0 commit comments

Comments
 (0)