Description
🔎 Search Terms
NodeJS 22
Typescript 5.5.4
test runner
assertions
🕗 Version & Regression Information
- This changed between versions 3.6.3 and 5.5.4
- I was unable to test this on prior versions because the Test runner was introduced as experimental in Node 18, and was made stable in Node 20.
⏯ Playground Link
💻 Code
// https://nodejs.org/docs/latest/api/test.html#contextassert
import { test } from 'node:test';
// Broken
test('test', (t) => {
t.assert.strictEqual(true, true);
});
import { TestContext } from 'node:test';
// Working
test('test', (t: TestContext) => {
t.assert.strictEqual(true, true);
});
🙁 Actual behavior
Assertions require every name in the call target to be declared with an explicit type annotation.(2775)
input.tsx(5, 15): 't' needs an explicit type annotation.
(property) TestContextAssert.strictEqual: (actual: unknown, expected: true, message?: string | Error) => asserts actual is true
Tests strict equality between the actual and expected parameters as determined by Object.is().
import assert from 'node:assert/strict';
assert.strictEqual(1, 2);
// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:
//
// 1 !== 2
🙂 Expected behavior
// Both cases should be treated the same way.
test('test', (t) => {
t.assert.strictEqual(true, true);
});
test('test', (t: TestContext) => {
t.assert.strictEqual(true, true);
});
Additional information about the issue
Test example taken directly from NodeJS 22 documentation
https://nodejs.org/api/test.html#contextassert