-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(finally): add finally method to AsyncAF & AsyncAfWrapper
- Loading branch information
1 parent
f4fc800
commit 8d6bf2e
Showing
2 changed files
with
24 additions
and
0 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 AsyncAF from '../../../dist/async-af'; | ||
|
||
describe('finally method', () => { | ||
it('should not receive any argument', async () => { | ||
let undefinedVar; | ||
await AsyncAF(6).then(n => n * 2).finally(n => { undefinedVar = n; }); | ||
expect(undefinedVar).to.be.undefined; | ||
}); | ||
it('should call onFinally after resolving', async () => { | ||
const arr = []; | ||
await AsyncAF(1).then(n => arr.push(n)).finally(() => arr.push(2)); | ||
expect(arr).to.eql([1, 2]); | ||
}); | ||
it('should call onFinally after rejecting', async () => { | ||
const arr = []; | ||
await AsyncAF(6).then(() => { throw Error(); }).catch(e => e).finally(() => arr.push(1)); | ||
expect(arr).to.eql([1]); | ||
}); | ||
}); |