fix(reactivity): should trigger collection's write-function correctly on non-reactive keys (#1992)
This commit is contained in:
@@ -1,6 +1,13 @@
|
||||
import { reactive, effect, isReactive, toRaw } from '../../src'
|
||||
|
||||
describe('reactivity/collections', () => {
|
||||
function coverCollectionFn(collection: Set<any>, fnName: string) {
|
||||
const spy = jest.fn()
|
||||
let proxy = reactive(collection)
|
||||
;(collection as any)[fnName] = spy
|
||||
return [proxy as any, spy]
|
||||
}
|
||||
|
||||
describe('Set', () => {
|
||||
it('instanceof', () => {
|
||||
const original = new Set()
|
||||
@@ -423,5 +430,29 @@ describe('reactivity/collections', () => {
|
||||
}, thisArg)
|
||||
expect(count).toBe(1)
|
||||
})
|
||||
|
||||
it('should trigger Set.has only once for non-reactive keys', () => {
|
||||
const [proxy, spy] = coverCollectionFn(new Set(), 'has')
|
||||
proxy.has('foo')
|
||||
expect(spy).toBeCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should trigger Set.add only once for non-reactive keys', () => {
|
||||
const [proxy, spy] = coverCollectionFn(new Set(), 'add')
|
||||
proxy.add('foo')
|
||||
expect(spy).toBeCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should trigger Set.delete only once for non-reactive keys', () => {
|
||||
const [proxy, spy] = coverCollectionFn(new Set(), 'delete')
|
||||
proxy.delete('foo')
|
||||
expect(spy).toBeCalledTimes(1)
|
||||
})
|
||||
|
||||
it('should trigger Set.clear only once for non-reactive keys', () => {
|
||||
const [proxy, spy] = coverCollectionFn(new Set(), 'clear')
|
||||
proxy.clear()
|
||||
expect(spy).toBeCalledTimes(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user