Complete the code to import the Node.js built-in test module.
import [1] from 'node:test';
The Node.js built-in test runner is imported using test from the node:test module.
Complete the code to define a test case using the Node.js built-in test runner.
test('addition works', () => { const result = 2 + 3; [1].strictEqual(result, 5); });
The assert module is used to check if the test result matches the expected value.
Fix the error in the test function declaration to correctly use the Node.js test runner.
import test from 'node:test'; import assert from 'node:assert'; test('check truth', async () => { const value = true; [1].ok(value); });
The assert module provides the ok method to check if a value is truthy.
Fill both blanks to create a test that checks if a function throws an error.
test('throws error', () => { [1](() => { throw new Error('fail'); }, [2]); });
console.log instead of assert.throws.assert.ok instead of a regex.The assert.throws method checks if a function throws an error matching the given regular expression.
Fill the blanks to write a test that checks if an async function resolves correctly.
test('async test', async () => { const data = await fetchData(); [1].strictEqual(typeof [2], 'string'); });
done() unnecessarily in async tests with Node.js built-in test runner.console instead of assert.The assert.strictEqual checks if the type of data is 'string'. The Node.js built-in test runner natively supports async functions with await, so no done() callback is needed.