Skip to content

tests: review and fix ineffective error tests #26385

@ChALkeR

Description

@ChALkeR

See #26078 (review) for context.

After that, I looked up if we already have similar ineffective tests in our codebase, and I think that I found at least one.

E.g. using grep -r ' catch' test/ -A 2 | grep strictEqual, this one popped up half through the list:

readable.destroy(err);
try {
await readable[Symbol.asyncIterator]().next();
} catch (e) {
assert.strictEqual(e, err);
}
}

The code above doesn't test that the error is thrown (as it likely should), instead it tests that another error doesn't get thrown.

Note that there are a lot of false positives in the said grep (actually most matches are false positives), because e.g. this is perfectly fine:

try {
await evaluatePromise;
} catch (err) {
assert.strictEqual(m.error, err);
return;
}
assert.fail('Missing expected exception');

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueIssues that are suitable for first-time contributors.help wantedIssues that need assistance from volunteers or PRs that need help to proceed.testIssues and PRs related to the tests.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions