Skip to content

Allow throws to accept a fn/Promise that throws anything #3245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Spell out boolean in error message and add tests
  • Loading branch information
novemberborn committed Sep 10, 2023
commit 97d8ee5b00c52dded8d84b98f123f9d53d7fbdec
2 changes: 1 addition & 1 deletion lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function validateExpectations(assertion, expectations, numberArgs) { // eslint-d
if (Object.hasOwn(expectations, 'any') && typeof expectations.any !== 'boolean') {
throw new AssertionError({
assertion,
message: `The \`any\` property of the second argument to \`t.${assertion}()\` must be a bool`,
message: `The \`any\` property of the second argument to \`t.${assertion}()\` must be a boolean`,
values: [formatWithLabel('Called with:', expectations)],
});
}
Expand Down
12 changes: 12 additions & 0 deletions test-tap/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -1167,6 +1167,12 @@ test('.throws() fails if passed a bad expectation', t => {
values: [{label: 'Called with:', formatted: /\[]/}],
});

failsWith(t, () => assertions.throws(() => {}, {any: {}}), {
assertion: 'throws',
message: 'The `any` property of the second argument to `t.throws()` must be a boolean',
values: [{label: 'Called with:', formatted: /any: {}/}],
});

failsWith(t, () => assertions.throws(() => {}, {code: {}}), {
assertion: 'throws',
message: 'The `code` property of the second argument to `t.throws()` must be a string or number',
Expand Down Expand Up @@ -1237,6 +1243,12 @@ test('.throwsAsync() fails if passed a bad expectation', t => {
values: [{label: 'Called with:', formatted: /\[]/}],
}, {expectBoolean: false});

failsWith(t, () => assertions.throwsAsync(() => {}, {any: {}}), {
assertion: 'throwsAsync',
message: 'The `any` property of the second argument to `t.throwsAsync()` must be a boolean',
values: [{label: 'Called with:', formatted: /any: {}/}],
}, {expectBoolean: false});

failsWith(t, () => assertions.throwsAsync(() => {}, {code: {}}), {
assertion: 'throwsAsync',
message: 'The `code` property of the second argument to `t.throwsAsync()` must be a string or number',
Expand Down