1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-25 15:29:32 -05:00

improve deferred test (#5459)

This commit is contained in:
Henry Zhuang 2020-05-16 06:59:44 +10:00 committed by GitHub
parent 0e4a927bcf
commit e98b759446
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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;
});
});