Skip to content

Commit 0f5a8ff

Browse files
committed
test: recurse effect
1 parent 0041ddc commit 0f5a8ff

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

tests/effect.spec.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { expect, test } from 'vitest';
2-
import { computed, effect, effectScope, endBatch, setActiveSub, signal, startBatch } from '../src';
2+
import { computed, effect, effectScope, endBatch, getActiveSub, setActiveSub, signal, startBatch } from '../src';
3+
import { ReactiveFlags } from '../src/system';
34

45
test('should clear subscriptions when untracked by all subscribers', () => {
56
let bRunTimes = 0;
@@ -271,3 +272,17 @@ test('should handle effect recursion for the first execution', () => {
271272
expect(triggers1).toBe(1);
272273
expect(triggers2).toBe(1);
273274
});
275+
276+
test('should support custom recurse effect', () => {
277+
const src = signal(0);
278+
279+
let triggers = 0;
280+
281+
effect(() => {
282+
getActiveSub()!.flags &= ~ReactiveFlags.RecursedCheck;
283+
triggers++;
284+
src(Math.min(src() + 1, 5));
285+
});
286+
287+
expect(triggers).toBe(6);
288+
});

0 commit comments

Comments
 (0)