Skip to content

Commit

Permalink
chore: add test for effect() on-demand trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Apr 6, 2023
1 parent f3a0071 commit 998c400
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/reactivity/__tests__/computed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,34 @@ describe('reactivity/computed', () => {
expect(hourSpy).toHaveBeenCalledTimes(17)
})

it('effect callback on-demand trigger', () => {
const minSpy = vi.fn()
const hourSpy = vi.fn()
const effectSpy = vi.fn()

const sec = ref(0)
const min = computed(() => {
minSpy()
return Math.floor(sec.value / 60)
})
const hour = computed(() => {
hourSpy()
return Math.floor(min.value / 60)
})

effect(() => {
effectSpy()
min.value
hour.value
})

for (sec.value = 0; sec.value < 1000; sec.value++) {}

expect(minSpy).toHaveBeenCalledTimes(1001)
expect(hourSpy).toHaveBeenCalledTimes(17)
expect(effectSpy).toHaveBeenCalledTimes(1001)
})

it('chained computed value urgent assessment edge case', () => {
const cSpy = vi.fn()

Expand Down

0 comments on commit 998c400

Please sign in to comment.