Challenge - 5 Problems
Deno Testing Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateWhy does Deno's built-in testing reduce setup time?
Deno includes a built-in test runner. What is the main reason this feature reduces setup time for developers?
Attempts:
2 left
💡 Hint
Think about what 'built-in' means for a developer starting a project.
✗ Incorrect
Deno's built-in testing means you don't need to install or configure separate testing tools. You can write and run tests immediately, saving setup time.
❓ component_behavior
intermediateHow does Deno's test runner handle asynchronous tests?
Consider this Deno test code snippet:
```ts
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts";
Deno.test("async test example", async () => {
const result = await Promise.resolve(5);
assertEquals(result, 5);
});
```
What will happen when this test runs?
Attempts:
2 left
💡 Hint
Think about whether Deno's test runner supports promises.
✗ Incorrect
Deno's test runner fully supports async functions, so tests that return promises run correctly and wait for completion.
🔧 Debug
advancedIdentify the error in this Deno test code
What error will this Deno test code produce when run?
```ts
Deno.test("failing test", () => {
throw new Error("Test failure");
});
```
Attempts:
2 left
💡 Hint
What happens when a test throws an error?
✗ Incorrect
If a test throws an error, Deno's test runner marks it as failed and shows the error message.
📝 Syntax
advancedWhich Deno test syntax correctly uses the test step feature?
Deno supports test steps to organize tests. Which option shows the correct way to use test steps?
Attempts:
2 left
💡 Hint
Look for the correct method call on the test context parameter.
✗ Incorrect
Test steps are created by calling t.step inside a test function that receives the test context t.
❓ state_output
expertWhat is the output of running this Deno test file?
Given this Deno test file content:
```ts
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts";
let counter = 0;
Deno.test("increment test", () => {
counter += 1;
assertEquals(counter, 1);
});
Deno.test("increment test again", () => {
counter += 1;
assertEquals(counter, 2);
});
```
What will be the result when running this file with `deno test`?
Attempts:
2 left
💡 Hint
Consider how variables behave across multiple tests in the same file.
✗ Incorrect
Since the tests run sequentially in the same process, the counter variable keeps its value between tests, so both assertions pass.
