Skip to content

Commit a89b8b8

Browse files
committed
Added test to make sure that error thrown from the producer function does not get swallowed
1 parent a92b20c commit a89b8b8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/create-sequence.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,21 @@ describe('Create sequence', () => {
139139
expect(received).toEqual(['a', 'b', 'c']);
140140
});
141141

142+
test('Error thrown from producer should not be swallowed', () => {
143+
const producer = function* () {
144+
yield 'a';
145+
yield 'b';
146+
throw new Error('Thrown from producer');
147+
// noinspection UnreachableCodeJS
148+
yield 'c';
149+
};
150+
const sequence = createSequence(producer);
151+
expect(sequence()).toEqual('a');
152+
expect(sequence()).toEqual('b');
153+
expect(() => sequence()).toThrow('Thrown from producer');
154+
expect(sequence()).toBeUndefined();
155+
});
156+
142157
test('It is allowed to mix access of sequence values', () => {
143158
const sequence = createSequence(['a', 'b', 'c', 'd', 'e', 'f']);
144159
const received = [];

0 commit comments

Comments
 (0)