Complete the code to declare an async test function in Deno.
Deno.test("example test", async () => { await [1]; });
The test function must await a Promise to handle async code properly. Promise.resolve() returns a resolved Promise immediately, making it suitable here.
Complete the code to test an async function that returns a value.
Deno.test("async value test", async () => { const result = await getValue(); if (result !== [1]) throw new Error("Wrong value"); });
The test expects the async function getValue() to return the string "success". The blank must match this expected value.
Fix the error in the async test by completing the code.
Deno.test("error test", async () => { try { await asyncFail(); } catch ([1]) { return; } throw new Error("Did not throw"); });
The catch block needs a variable name to capture the thrown error. "e" is a common and valid choice here.
Fill both blanks to create a test that waits for a promise and asserts its result.
Deno.test("promise test", async () => { const data = await fetchData(); if (data.status [1] 200) throw new Error("Status not OK"); if (data.body [2] "") throw new Error("Empty body"); });
The first condition checks if status is not equal to 200 using "!==". The second checks if body is equal to empty string using "===".
Fill all three blanks to create a test that mocks an async function and checks the call count.
const mockFn = [1](() => Promise.resolve(42)); Deno.test("mock call count", async () => { await mockFn(); if (mockFn.[2] !== [3]) throw new Error("Wrong call count"); });
Using Sinon, sinon.stub creates the mock function. The call count is checked by mockFn.calls.length, expecting 1 call.
