Skip to content

Commit

Permalink
Merge pull request #3 from vadzim/master
Browse files Browse the repository at this point in the history
do not throw on non-thenables
  • Loading branch information
xobotyi authored Aug 6, 2018
2 parents 6f9cb8b + 7e0f159 commit b5fd791
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/await-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @return {Promise<Array>} Array with `[results, error]`
*/
export default function of(promise) {
return promise
return Promise.resolve(promise)
.then((ret) => [ret])
.catch((err) => {
if (err === undefined || err === null) {
Expand Down
16 changes: 16 additions & 0 deletions tests/await-of.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@ describe("await-of test",
expect(err.originalValue).toBeUndefined();
expect(err.message).toEqual('Rejection with empty value');
});

it("should not throw on non-thenables", async () => {
const result = "Hello world!";
const [data, err] = await of(result);

expect(err).toBeUndefined();
expect(data).toEqual(result);
});

it("should not throw on nulls", async () => {
const result = null;
const [data, err] = await of(result);

expect(err).toBeUndefined();
expect(data).toEqual(result);
});
});

0 comments on commit b5fd791

Please sign in to comment.