Skip to content

Commit

Permalink
feat(finally): add finally method to AsyncAF & AsyncAfWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottRudiger committed May 21, 2018
1 parent f4fc800 commit 8d6bf2e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/classes/AsyncAfWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class AsyncAfWrapperProto {
catch(reject) {
return this.then(null, reject);
}
finally(onFinally) {
return this.data.finally(onFinally);
}
}

class AsyncAfWrapper extends AsyncAfWrapperProto {}
Expand Down
21 changes: 21 additions & 0 deletions test/methods/other/finally.test.js
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]);
});
});

0 comments on commit 8d6bf2e

Please sign in to comment.