Skip to content

Commit

Permalink
test(effect): verify cleanupEffect clears multiple dependencies (#9503)
Browse files Browse the repository at this point in the history
close #5541
  • Loading branch information
jh-leong authored Jun 6, 2024
1 parent 71c2c0a commit d04417d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions packages/reactivity/__tests__/effect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,31 @@ describe('reactivity/effect', () => {
expect(dummy).toBe(3)
})

it('stop with multiple dependencies', () => {
let dummy1, dummy2
const obj1 = reactive({ prop: 1 })
const obj2 = reactive({ prop: 1 })
const runner = effect(() => {
dummy1 = obj1.prop
dummy2 = obj2.prop
})

obj1.prop = 2
expect(dummy1).toBe(2)

obj2.prop = 3
expect(dummy2).toBe(3)

stop(runner)

obj1.prop = 4
obj2.prop = 5

// Check that both dependencies have been cleared
expect(dummy1).toBe(2)
expect(dummy2).toBe(3)
})

it('events: onStop', () => {
const onStop = vi.fn()
const runner = effect(() => {}, {
Expand Down

0 comments on commit d04417d

Please sign in to comment.