Challenge - 5 Problems
Deno Test Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat is the output of this Deno test function?
Consider this Deno test function. What will be printed when you run it with
deno test?Deno
import { assertEquals } from "https://deno.land/std@0.203.0/testing/asserts.ts"; test("sum test", () => { const result = 2 + 3; console.log("Inside test"); assertEquals(result, 5); });
Attempts:
2 left
💡 Hint
Remember that console.log inside a test function runs when the test runs.
✗ Incorrect
The console.log inside the test function runs during the test execution, so "Inside test" is printed. The assertion passes, so the test passes.
📝 Syntax
intermediateWhich option correctly defines an async test function in Deno?
You want to write an async test function in Deno that awaits a promise. Which option is syntactically correct?
Attempts:
2 left
💡 Hint
Check the syntax for async arrow functions.
✗ Incorrect
Option B correctly uses an async arrow function with parentheses and braces and includes the test name. Option B misses the test name and uses function keyword without name. Option B has invalid async parameter. Option B misses the test name argument which is required.
🔧 Debug
advancedWhy does this Deno test fail with a timeout?
This test never finishes and times out. Why?
test("timeout test", async () => {
setTimeout(() => {
console.log("Done");
}, 1000);
});Attempts:
2 left
💡 Hint
Think about how async functions and timers work together.
✗ Incorrect
The test function finishes immediately because setTimeout callback is not awaited or wrapped in a promise. The test runner waits for the async function to complete, but the timer callback runs later, causing a timeout.
❓ state_output
advancedWhat is the value of count after running this Deno test?
Given this code, what is the final value of
count after the test finishes?
let count = 0;
test("increment count", () => {
count += 1;
});
count += 1;Attempts:
2 left
💡 Hint
Remember the order of code execution outside and inside tests.
✗ Incorrect
The code increments count by 1 outside the test, then the test runs and increments count by 1 again, so total is 2.
🧠 Conceptual
expertWhich option best describes Deno's test runner behavior with multiple tests?
You have multiple tests defined with
test() in a file. How does Deno's test runner execute them by default?Attempts:
2 left
💡 Hint
Think about test isolation and order guarantees.
✗ Incorrect
By default, Deno runs tests sequentially in the order they are defined to avoid race conditions and ensure predictable results.
