Performance: Async test patterns
This affects test execution speed and responsiveness during asynchronous operations in tests.
Deno.test("good async test", async () => { const response = await fetch("https://example.com"); const data = await response.json(); if (!data) throw new Error("No data"); });
Deno.test("bad async test", () => { const result = fetch("https://example.com"); const data = result.then(res => res.json()); // No await, test ends before promise resolves if (!data) throw new Error("No data"); });
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Callback without await | N/A | N/A | N/A | [X] Bad |
| Sequential await | N/A | N/A | N/A | [!] OK |
| Parallel await with Promise.all | N/A | N/A | N/A | [OK] Good |
async and await in Deno test functions?import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
Deno.test("delayed test", async () => {
const result = await new Promise((resolve) => setTimeout(() => resolve(42), 100));
assertEquals(result, 42);
});import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
Deno.test("broken test", () => {
const result = await Promise.resolve(10);
assertEquals(result, 10);
});fetchData() that returns a promise resolving to an object. Which pattern correctly tests it with Deno's async test and handles errors gracefully?Pass the test and this pattern moves unknown