-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for WasmQueue JS module (#141)
* Merge WASM Loader and WASM Queue * Add tests for WasmQueue module
- Loading branch information
1 parent
10073f3
commit 33a9f9d
Showing
6 changed files
with
84 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
export const wasm_search = jest.fn; | ||
export default jest.fn().mockImplementation((input: string) => { | ||
return new Promise((res, rej) => { | ||
if (input.includes("stork-search.net")) { | ||
res(); | ||
return; | ||
} else { | ||
rej(); | ||
} | ||
}); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,31 @@ | ||
import WasmQueue from "./wasmQueue"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-function | ||
jest.mock("stork-search", undefined, { virtual: true }); | ||
|
||
test.each([ | ||
[null, true, [true, true, false, false]], | ||
["https://google.com", false, [false, false, false, true]] | ||
])( | ||
"Test WasmQueue Loads %s %s", | ||
async (initValue, expectedIsLoaded, expectedMockCalls) => { | ||
const successFxns = [jest.fn(), jest.fn()]; | ||
const failureFxns = [jest.fn(), jest.fn()]; | ||
const queue = new WasmQueue(initValue) | ||
.runAfterWasmLoaded(successFxns[0]) | ||
.runAfterWasmLoaded(successFxns[1]) | ||
.runOnWasmLoadFailure(failureFxns[0]) | ||
.runOnWasmLoadFailure(failureFxns[1]); | ||
|
||
await queue.wasmLoadPromise; | ||
|
||
expect(queue.wasmIsLoaded).toBe(expectedIsLoaded); | ||
|
||
const computed = [...successFxns, ...failureFxns].map( | ||
// Did the function get called exactly once? | ||
fn => fn.mock.calls.length === 1 | ||
); | ||
|
||
expect(computed).toEqual(expectedMockCalls); | ||
} | ||
); |
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