test(reactivity): check for key in entries iteration (#152)

This commit is contained in:
夜宴 2019-10-08 10:00:20 -05:00 committed by Evan You
parent 16da9ae89f
commit 8d10096d24

View File

@ -127,25 +127,32 @@ describe('reactivity/collections', () => {
it('should observe entries iteration', () => { it('should observe entries iteration', () => {
let dummy let dummy
let dummy2
const map = reactive(new Map()) const map = reactive(new Map())
effect(() => { effect(() => {
dummy = 0 dummy = ''
dummy2 = 0
// eslint-disable-next-line no-unused-vars // eslint-disable-next-line no-unused-vars
for (let [key, num] of map.entries()) { for (let [key, num] of map.entries()) {
key dummy += key
dummy += num dummy2 += num
} }
}) })
expect(dummy).toBe(0) expect(dummy).toBe('')
expect(dummy2).toBe(0)
map.set('key1', 3) map.set('key1', 3)
expect(dummy).toBe(3) expect(dummy).toBe('key1')
expect(dummy2).toBe(3)
map.set('key2', 2) map.set('key2', 2)
expect(dummy).toBe(5) expect(dummy).toBe('key1key2')
expect(dummy2).toBe(5)
map.delete('key1') map.delete('key1')
expect(dummy).toBe(2) expect(dummy).toBe('key2')
expect(dummy2).toBe(2)
map.clear() map.clear()
expect(dummy).toBe(0) expect(dummy).toBe('')
expect(dummy2).toBe(0)
}) })
it('should be triggered by clearing', () => { it('should be triggered by clearing', () => {