-
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.
- Loading branch information
Showing
5 changed files
with
118 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { | ||
expect, | ||
} from "chai"; | ||
|
||
import { | ||
spy, | ||
} from "sinon"; | ||
|
||
import delay from "./delay"; | ||
|
||
describe(delay.name || "delay", () => { | ||
it("should return a 'Promise'", () => { | ||
expect(delay(0)).to.be.instanceOf(Promise); | ||
}); | ||
it("should be working with negative timeout", async () => { | ||
await delay(-100); | ||
}); | ||
it("should resolve value", async () => { | ||
expect(await delay(0, "abc")).to.be.equal("abc"); | ||
}); | ||
it("should resolve value from 'Promise'", async () => { | ||
expect(await delay(0, Promise.resolve("abc"))).to.be.equal("abc"); | ||
}); | ||
it("should reject value from 'Promise'", (done) => { | ||
const reject = Promise.reject(new Error()); | ||
reject.catch(() => void 0); | ||
delay(0, reject).catch(() => { done(); }); | ||
}); | ||
}); |
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,13 @@ | ||
/** | ||
* delay the execution by given amount of time | ||
* | ||
* @param delay time in milliseconds | ||
* @param val optional value to return | ||
*/ | ||
export default <T = void>(delay: number, val?: T | PromiseLike<T>) => new Promise<T>( | ||
(resolve) => { | ||
setTimeout(() => { | ||
resolve(val); | ||
}, delay); | ||
}, | ||
); |
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