Complete the code to define a test function in Deno.
Deno.test("example test", () => { const result = 1 + 1; if (result !== [1]) throw new Error("Test failed"); });
The test checks if 1 + 1 equals 2, so the correct expected value is 2.
Complete the code to import the assertEquals function from Deno's standard testing library.
import { [1] } from "https://deno.land/std/testing/asserts.ts";
assertEquals is used to compare expected and actual values in tests.
Fix the error in the test function by completing the assertion call.
import { assertEquals } from "https://deno.land/std/testing/asserts.ts"; Deno.test("sum test", () => { const sum = 2 + 3; [1](sum, 5); });
assertEquals is used to check if sum equals 5.
Fill both blanks to write a test that checks if a function throws an error.
import { [1] } from "https://deno.land/std/testing/asserts.ts"; Deno.test("error test", () => { [2](() => { throw new Error("fail"); }); });
assertThrows is used to check if a function throws an error.
Fill all three blanks to write a test that checks if a function returns the expected value.
import { [1] } from "https://deno.land/std/testing/asserts.ts"; function greet(name) { return `Hello, ${name}!`; } Deno.test("greet test", () => { const message = greet("Alice"); [2](message, [3]); });
assertEquals is imported and used to check if the message equals the expected greeting string.
