-
Notifications
You must be signed in to change notification settings - Fork 520
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
refactor: move tryFunctions to core and include tests
1 parent
7d05c68
commit c7b97e2
Showing
5 changed files
with
49 additions
and
19 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
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
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,28 @@ | ||
/*! | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
import { tryFunctions } from '../../../shared/utilities/tsUtils' | ||
import assert from 'assert' | ||
|
||
describe('tryFunctions', function () { | ||
it('should return the result of the first function that returns', async function () { | ||
const f1 = () => Promise.reject('f1') | ||
const f2 = () => Promise.resolve('f2') | ||
const f3 = () => Promise.reject('f3') | ||
|
||
assert.strictEqual(await tryFunctions([f1, f2, f3]), 'f2') | ||
}) | ||
|
||
it('if all reject, then should throw final error', async function () { | ||
const f1 = () => Promise.reject('f1') | ||
const f2 = () => Promise.reject('f2') | ||
const f3 = () => Promise.reject('f3') | ||
|
||
await assert.rejects( | ||
async () => await tryFunctions([f1, f2, f3]), | ||
(e) => e === 'f3' | ||
) | ||
}) | ||
}) |