Skip to content

Commit 3524a3f

Browse files
authored
test: adds test for synchronous generator (#19)
Adds additional test from #18 to prevent future regressions
1 parent 66af3c8 commit 3524a3f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

test/index.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,20 @@ describe('abortable-iterator', () => {
227227
))
228228
.to.eventually.be.rejected.with.property('type', 'aborted')
229229
})
230+
231+
it('should abort a synchronous generator', async () => {
232+
const controller = new AbortController()
233+
const iterator = abortableSource((function * () {
234+
while (true) {
235+
yield Math.random()
236+
}
237+
})(), controller.signal)
238+
239+
await expect((async () => {
240+
for await (const _ of iterator) { // eslint-disable-line @typescript-eslint/no-unused-vars
241+
controller.abort()
242+
}
243+
})())
244+
.to.eventually.be.rejected.with.property('type', 'aborted')
245+
})
230246
})

0 commit comments

Comments
 (0)