mirror of
https://github.com/denoland/std.git
synced 2024-11-21 20:50:22 +00:00
improve deferred test (denoland/deno#5459)
This commit is contained in:
parent
e43474e6d8
commit
eec6ed601e
@ -1,8 +1,17 @@
|
||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||
import { assertEquals, assertThrowsAsync } from "../testing/asserts.ts";
|
||||
import { deferred } from "./deferred.ts";
|
||||
|
||||
Deno.test("[async] deferred", function (): Promise<void> {
|
||||
const d = deferred<number>();
|
||||
d.resolve(12);
|
||||
return Promise.resolve();
|
||||
Deno.test("[async] deferred: resolve", async function (): Promise<void> {
|
||||
const d = deferred<string>();
|
||||
d.resolve("🦕");
|
||||
assertEquals(await d, "🦕");
|
||||
});
|
||||
|
||||
Deno.test("[async] deferred: reject", async function (): Promise<void> {
|
||||
const d = deferred<number>();
|
||||
d.reject(new Error("A deno error 🦕"));
|
||||
await assertThrowsAsync(async () => {
|
||||
await d;
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user