-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Task.allSuccesses and Task.prototype.validateError
- Loading branch information
Showing
6 changed files
with
169 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { allSuccesses, failIn, succeedIn } from "../Task" | ||
import { ERROR_RESULT } from "./util" | ||
|
||
describe("allSuccesses", () => { | ||
test("should run all tasks in parallel and return an array of results in their original order", () => { | ||
const resolve = jest.fn() | ||
const reject = jest.fn() | ||
|
||
allSuccesses([succeedIn(200, "A"), succeedIn(100, "B")]).fork( | ||
reject, | ||
resolve, | ||
) | ||
|
||
jest.advanceTimersByTime(250) | ||
|
||
expect(reject).not.toBeCalled() | ||
expect(resolve).toBeCalledWith(["B", "A"]) | ||
}) | ||
|
||
test("should allow errors", () => { | ||
const resolve = jest.fn() | ||
const reject = jest.fn() | ||
|
||
allSuccesses([failIn(200, ERROR_RESULT), succeedIn(100, "B")]).fork( | ||
reject, | ||
resolve, | ||
) | ||
|
||
jest.advanceTimersByTime(250) | ||
|
||
expect(reject).not.toBeCalled() | ||
expect(resolve).toBeCalledWith(["B"]) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,2 +1,8 @@ | ||
export const SUCCESS_RESULT = "__SUCCESS__" | ||
export const ERROR_RESULT = "__ERROR__" | ||
|
||
export type SUCCESS_TYPE = "__SUCCESS__" | ||
export type ERROR_TYPE = "__ERROR__" | ||
|
||
export const isSuccess = (v: unknown): v is SUCCESS_TYPE => v === SUCCESS_RESULT | ||
export const isError = (v: unknown): v is ERROR_TYPE => v === ERROR_RESULT |