Skip to content

Commit f3a0071

Browse files
johnsoncodehkyyx990803
authored andcommitted
feat: more purposeful test
1 parent eb0f8fa commit f3a0071

File tree

1 file changed

+14
-43
lines changed

1 file changed

+14
-43
lines changed

packages/reactivity/__tests__/computed.spec.ts

+14-43
Original file line numberDiff line numberDiff line change
@@ -292,54 +292,25 @@ describe('reactivity/computed', () => {
292292
})
293293

294294
it('chained computed value on-demand trigger', () => {
295-
const c1Spy = vi.fn()
296-
const c2Spy = vi.fn()
295+
const minSpy = vi.fn()
296+
const hourSpy = vi.fn()
297297

298-
const src = ref(0)
299-
const c1 = computed(() => {
300-
c1Spy()
301-
return src.value < 5
298+
const sec = ref(0)
299+
const min = computed(() => {
300+
minSpy()
301+
return Math.floor(sec.value / 60)
302302
})
303-
const c2 = computed(() => {
304-
c2Spy()
305-
return c1.value ? '< 5' : '>= 5'
303+
const hour = computed(() => {
304+
hourSpy()
305+
return Math.floor(min.value / 60)
306306
})
307307

308-
expect(c1Spy).toHaveBeenCalledTimes(0)
309-
expect(c2Spy).toHaveBeenCalledTimes(0)
310-
311-
expect(src.value).toBe(0)
312-
expect(c2.value).toBe('< 5')
313-
expect(c1Spy).toHaveBeenCalledTimes(1)
314-
expect(c2Spy).toHaveBeenCalledTimes(1)
315-
316-
src.value++
317-
expect(c2.value).toBe('< 5')
318-
expect(c1Spy).toHaveBeenCalledTimes(2)
319-
expect(c2Spy).toHaveBeenCalledTimes(1)
320-
321-
for (let i = 0; i < 10; i++) {
322-
src.value++
308+
for (sec.value = 0; sec.value < 1000; sec.value++) {
309+
hour.value
323310
}
324-
expect(src.value).toBe(11)
325-
expect(c2.value).toBe('>= 5')
326-
expect(c1Spy).toHaveBeenCalledTimes(3)
327-
expect(c2Spy).toHaveBeenCalledTimes(2)
328-
329-
src.value++
330-
expect(src.value).toBe(12)
331-
expect(c2.value).toBe('>= 5')
332-
expect(c1Spy).toHaveBeenCalledTimes(4)
333-
expect(c2Spy).toHaveBeenCalledTimes(2)
334-
335-
for (let i = 0; i < 100; i++) {
336-
src.value++
337-
c2.value
338-
}
339-
expect(src.value).toBe(112)
340-
expect(c2.value).toBe('>= 5')
341-
expect(c1Spy).toHaveBeenCalledTimes(104)
342-
expect(c2Spy).toHaveBeenCalledTimes(2)
311+
312+
expect(minSpy).toHaveBeenCalledTimes(1000)
313+
expect(hourSpy).toHaveBeenCalledTimes(17)
343314
})
344315

345316
it('chained computed value urgent assessment edge case', () => {

0 commit comments

Comments
 (0)