Bird
Raised Fist0
Denoframework~20 mins

deno test for testing - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Deno Testing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2:00remaining
What is the output of this Deno test?
Consider this Deno test code. What will be the test result output when running deno test?
Deno
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts";

Deno.test("sum test", () => {
  const result = 2 + 3;
  assertEquals(result, 5);
});
AThe test fails with an assertion error.
BThe test passes with no errors.
CSyntaxError due to missing async keyword.
DRuntime error because assertEquals is not imported.
Attempts:
2 left
💡 Hint
Check if the assertion matches the expected value.
📝 Syntax
intermediate
2:00remaining
Which option causes a syntax error in Deno test?
Identify which test code snippet will cause a syntax error when running deno test.
ADeno.test "test", () => { assertEquals(1, 1); });
BDeno.test("test", async () => { await Promise.resolve(); });
C;)} ;)1 ,1(slauqEtressa { >= )( ,"tset"(tset.oneD
DDeno.test("test", () => { assertEquals(1, 1); });
Attempts:
2 left
💡 Hint
Look for missing parentheses or misplaced quotes.
❓ state_output
advanced
2:00remaining
What is the output of this asynchronous Deno test?
Given this Deno test code, what will be the test output?
Deno
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts";

Deno.test("async test", async () => {
  const value = await Promise.resolve(10);
  assertEquals(value, 10);
});
ATest fails due to assertion error.
BTest fails due to unhandled promise rejection.
CTest passes successfully.
DSyntax error because async is not allowed.
Attempts:
2 left
💡 Hint
Check if the awaited promise resolves to the expected value.
🔧 Debug
advanced
2:00remaining
Which option causes a runtime error in this Deno test?
Find the code snippet that will cause a runtime error when running deno test.
ADeno.test("test", () => { const x = undefinedVariable; });
BDeno.test("test", () => { 1 === 1; });
CDeno.test("test", () => { return true; });
DDeno.test("test", () => { throw new Error("fail"); });
Attempts:
2 left
💡 Hint
Look for undefined variables causing errors.
🧠 Conceptual
expert
3:00remaining
How many tests will run and what is the output?
Given this Deno test file, how many tests will run and what will be the overall result?
Deno
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts";

Deno.test("test 1", () => {
  assertEquals(1 + 1, 2);
});

Deno.test("test 2", () => {
  throw new Error("fail");
});

Deno.test("test 3", () => {
  assertEquals(3 * 3, 9);
});
A3 tests run; all pass successfully.
B2 tests run; 1 pass, 1 fails.
C1 test runs and it fails.
D3 tests run; 2 pass, 1 fails with error.
Attempts:
2 left
💡 Hint
Count all deno.test calls and check which throw errors.

Practice

(1/5)
1. What is the main purpose of using deno test in your code?
easy
A. To check if your code works as expected by running tests
B. To deploy your code to a server
C. To format your code automatically
D. To create a new Deno project

Solution

  1. Step 1: Understand the role of deno test

    deno test is a command used to run tests written in your code to verify correctness.

  2. Step 2: Compare with other options

    Deploying, formatting, or creating projects are not related to testing functionality.

  3. Final Answer:

    To check if your code works as expected by running tests -> Option A
  4. Quick Check:

    Testing = Check code correctness [OK]
Hint: Remember: testing means checking code correctness [OK]
Common Mistakes:
  • Confusing testing with deployment
  • Thinking deno test formats code
  • Assuming it creates projects
2. Which of the following is the correct way to write a simple test in Deno?
easy
A. deno.test(() => { assertEquals(1 + 1, 2); });
B. test deno { assertEquals(1 + 1, 2); }
C. deno.test = () => { assertEquals(1 + 1, 2); }
D. test(() => assertEquals(1 + 1, 2));

Solution

  1. Step 1: Identify correct test syntax in Deno

    The correct syntax uses deno.test as a function with a callback containing assertions.

  2. Step 2: Check each option

    deno.test(() => { assertEquals(1 + 1, 2); }); correctly uses deno.test(() => { ... }). Options A, B, and D have syntax errors or incorrect usage.

  3. Final Answer:

    deno.test(() => { assertEquals(1 + 1, 2); }); -> Option A
  4. Quick Check:

    Correct test syntax = deno.test(() => { assertEquals(1 + 1, 2); }); [OK]
Hint: Use deno.test with a function callback [OK]
Common Mistakes:
  • Using incorrect keywords like 'test deno'
  • Assigning instead of calling deno.test
  • Omitting 'deno.' prefix
3. What will be the output when running this test code with deno test?
import { assertEquals } from "https://deno.land/std@0.177.0/testing/asserts.ts";
deno.test("sum test", () => {
  assertEquals(2 + 2, 4);
});
medium
A. Syntax error due to import statement
B. Test fails with assertion error
C. Test passes with no errors
D. Runtime error: deno.test is not a function

Solution

  1. Step 1: Analyze the test code logic

    The test checks if 2 + 2 equals 4 using assertEquals, which is true.

  2. Step 2: Consider syntax and runtime

    The import statement is correct, and deno.test is valid in Deno environment.

  3. Final Answer:

    Test passes with no errors -> Option C
  4. Quick Check:

    Correct assertion = Test passes [OK]
Hint: True assertions mean passing tests [OK]
Common Mistakes:
  • Thinking import causes syntax error
  • Confusing assertion failure with success
  • Assuming deno.test is undefined
4. Identify the error in this test code snippet:
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
deno.test("check", () => {
  assertEquals(5, 2 + 2);
});
medium
A. assertEquals is not imported correctly
B. The assertion will fail because 5 is not equal to 4
C. deno.test is used incorrectly without a name
D. The import URL is missing the version number

Solution

  1. Step 1: Check the import statement

    The import URL lacks a version number, which is required for stable imports in Deno.

  2. Step 2: Verify other parts

    The assertion will fail logically, but the question asks for the error in the snippet, and missing version is a syntax/runtime error.

  3. Final Answer:

    The import URL is missing the version number -> Option D
  4. Quick Check:

    Stable imports need version numbers [OK]
Hint: Always include version in import URLs [OK]
Common Mistakes:
  • Ignoring missing version in import URL
  • Confusing assertion failure with syntax error
  • Assuming deno.test needs no name
5. You want to write multiple tests in one file using deno test. Which approach correctly groups tests with descriptive names and runs them all?
hard
A. Write one deno.test with multiple assertions but no names
B. Use multiple deno.test calls each with a unique name and callback function
C. Call deno.test inside a loop without names
D. Use deno.runTests() to run tests automatically

Solution

  1. Step 1: Understand how to organize multiple tests

    Each test should have a unique name and a callback function using deno.test.

  2. Step 2: Evaluate options

    Use multiple deno.test calls each with a unique name and callback function correctly uses multiple named tests. Write one deno.test with multiple assertions but no names lacks test names, making results unclear. Call deno.test inside a loop without names uses a loop without names, which is not recommended. Use deno.runTests() to run tests automatically is invalid; deno.runTests() does not exist.

  3. Final Answer:

    Use multiple deno.test calls each with a unique name and callback function -> Option B
  4. Quick Check:

    Multiple named tests = Use multiple deno.test calls each with a unique name and callback function [OK]
Hint: Name each test separately with deno.test [OK]
Common Mistakes:
  • Writing unnamed tests
  • Using loops without test names
  • Assuming deno.runTests() exists
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard