-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: propagate abort reason in derived signals
Fixes #101
- Loading branch information
1 parent
975fc44
commit 9cd7d79
Showing
3 changed files
with
27 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { expect } from 'chai'; | ||
import { deriveAbortController } from './abort'; | ||
|
||
describe('deriveAbortController', () => { | ||
it('should return an aborted AbortController when the provided signal is already aborted', () => { | ||
const parentCtrl = new AbortController(); | ||
parentCtrl.abort(new Error('asdf')); | ||
const { ctrl } = deriveAbortController(parentCtrl.signal); | ||
expect(ctrl.signal.aborted).to.be.true; | ||
expect(ctrl.signal.reason).to.equal(parentCtrl.signal.reason); | ||
}); | ||
|
||
it('should abort the new AbortController when the provided signal aborts', () => { | ||
const parentCtrl = new AbortController(); | ||
const { ctrl } = deriveAbortController(parentCtrl.signal); | ||
expect(ctrl.signal.aborted).to.be.false; | ||
parentCtrl.abort(new Error('asdf')); | ||
expect(ctrl.signal.aborted).to.be.true; | ||
expect(ctrl.signal.reason).to.equal(parentCtrl.signal.reason); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters