Skip to content

Commit 194f513

Browse files
committed
Add generator tests
1 parent 1d83254 commit 194f513

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

packages/base/src/utils/iterateEquals.spec.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,40 @@ describe.each([['normal'], ['flip']])('with %s order', mode => {
4545
test('null should be treated as an element', () => {
4646
expect(fn([].values(), [null].values())).toBe(false);
4747
});
48+
49+
test('generator should return true', () => {
50+
const generator = function* () {
51+
yield 1;
52+
yield 2;
53+
yield 3;
54+
};
55+
56+
expect(fn(generator(), generator())).toBe(true);
57+
});
58+
59+
test('generator should return false if more than 1M iterations', () => {
60+
const generator = function* () {
61+
for (let count = 0; count < 1_000_001; count++) {
62+
if (count === 1_000_000) {
63+
throw new Error('Should not iterate after 1M iterations');
64+
}
65+
66+
yield count;
67+
}
68+
};
69+
70+
expect(fn(generator(), generator())).toBe(false);
71+
});
72+
73+
test('should ignore return value from generator', () => {
74+
const generator = function* (returnValue: number) {
75+
yield 1;
76+
yield 2;
77+
yield 3;
78+
79+
return returnValue;
80+
};
81+
82+
expect(fn(generator(4), generator(5))).toBe(true);
83+
});
4884
});

0 commit comments

Comments
 (0)