Closed
Description
What is the problem this feature will solve?
The assertion module signals failures via exceptions. This may causes some subtle issues during program testing, since the "exception channel" is also used by the program under test which may catch the exceptions generated by failing assertions resulting in weird test behavior.
import {test} from "node:test";
import assert from "node:assert";
function function_under_test(callback, value) {
let r = 0;
try {
r = callback(value);
} catch (error) {
//log error...
}
//continue executing operations...
}
test("weird test supposed to fail, but it doesn't", function () {
function_under_test(function (v) {
assert.fail("BOOM!");
}, 4);
});
test passes...
What is the feature you are proposing to solve the problem?
When in a test runner context provide the assertion module via the testContext object:
import {test} from "node:test";
import assert from "node:assert";
function function_under_test(callback, value) {
let r = 0;
try {
r = callback(value);
} catch (error) {
//log error...
}
//continue executing operations...
}
test("weird test", function (testContext) {
function_under_test(function (v) {
testContext.assert.fail("BOOM!");
}, 4);
});
and signal the failures via messages between testContext and assert methods.
What alternatives have you considered?
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Awaiting Triage