Challenge - 5 Problems
Async Test Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat is the output of this async test using Deno's testing framework?
Consider this Deno test code snippet. What will be printed when the test runs?
Deno
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts"; deno.test("async addition test", async () => { const result = await Promise.resolve(5 + 3); console.log("Result is", result); assertEquals(result, 8); });
Attempts:
2 left
💡 Hint
Remember that await unwraps the Promise before logging.
✗ Incorrect
The await keyword unwraps the Promise, so the console.log prints the resolved value 8. The test passes and prints 'Result is 8'.
❓ state_output
intermediateWhat is the value of variable 'count' after this async test runs?
Look at this Deno test. What will be the final value of 'count' after the test completes?
Deno
let count = 0; deno.test("increment count asynchronously", async () => { await new Promise((resolve) => setTimeout(resolve, 50)); count += 1; });
Attempts:
2 left
💡 Hint
The test waits before incrementing count.
✗ Incorrect
The test awaits a 50ms delay, then increments count by 1. After the test finishes, count is 1.
🔧 Debug
advancedWhich option causes a test timeout error in Deno?
Given these test snippets, which one will cause Deno to report a timeout error?
Attempts:
2 left
💡 Hint
Look for a Promise that never resolves or rejects.
✗ Incorrect
Option A awaits a Promise that never resolves, causing the test to hang and eventually timeout.
📝 Syntax
advancedWhich option contains a syntax error in async test declaration?
Identify the option with invalid syntax for an async test in Deno.
Attempts:
2 left
💡 Hint
Check the order of parameters and keywords.
✗ Incorrect
Option C places the async keyword before the test name string, which is invalid syntax.
🧠 Conceptual
expertWhich option best explains why 'await' is necessary in Deno async tests?
Why must you use 'await' inside async Deno tests when calling asynchronous code?
Attempts:
2 left
💡 Hint
Think about test timing and when assertions run.
✗ Incorrect
Using await pauses the test until the async operation finishes, so assertions check the correct state.
