|
|
@@ -1136,4 +1136,21 @@ describe('api: watch', () => {
|
|
|
await nextTick()
|
|
|
expect(spy).toHaveBeenCalledTimes(2)
|
|
|
})
|
|
|
+
|
|
|
+ // #12643
|
|
|
+ test('should trigger watch on reactive object when new property is added via set()', () => {
|
|
|
+ const spy = vi.fn()
|
|
|
+ const obj = reactive({})
|
|
|
+ watch(obj, spy, { flush: 'sync' })
|
|
|
+ set(obj, 'foo', 1)
|
|
|
+ expect(spy).toHaveBeenCalled()
|
|
|
+ })
|
|
|
+
|
|
|
+ test('should not trigger watch when calling set() on ref value', () => {
|
|
|
+ const spy = vi.fn()
|
|
|
+ const r = ref({})
|
|
|
+ watch(r, spy, { flush: 'sync' })
|
|
|
+ set(r.value, 'foo', 1)
|
|
|
+ expect(spy).not.toHaveBeenCalled()
|
|
|
+ })
|
|
|
})
|