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
Disable lint rules inline
  • Loading branch information
novemberborn committed Sep 10, 2023
commit a64d2b13f48acf63d422ab64ba9971f27fda2f9c
8 changes: 0 additions & 8 deletions .xo-config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,5 @@ module.exports = {
'unicorn/error-message': 'off',
},
},
{
files: 'test-tap/assert.js',
rules: {
'prefer-promise-reject-errors': 'off',
'no-throw-literal': 'off',
},
},

],
};
6 changes: 3 additions & 3 deletions test-tap/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ test('.throws()', gather(t => {

// Passes when string is thrown, only when any is set to true.
passes(t, () => assertions.throws(() => {
throw 'foo';
throw 'foo'; // eslint-disable-line no-throw-literal
}, {any: true}));

// Passes because the correct error is thrown.
Expand Down Expand Up @@ -1046,7 +1046,7 @@ test('.throwsAsync()', gather(t => {
});

// Fails because the function returned a promise that rejected, but not with an error.
throwsAsyncFails(t, () => assertions.throwsAsync(() => Promise.reject('foo')), {
throwsAsyncFails(t, () => assertions.throwsAsync(() => Promise.reject('foo')), { // eslint-disable-line prefer-promise-reject-errors
assertion: 'throwsAsync',
message: '',
values: [{label: 'Returned promise rejected with exception that is not an error:', formatted: /'foo'/}],
Expand All @@ -1056,7 +1056,7 @@ test('.throwsAsync()', gather(t => {
throwsAsyncPasses(t, () => assertions.throwsAsync(Promise.reject(new Error())));

// Passes because the promise was rejected with an with an non-error exception, & set `any` to true in expectation.
throwsAsyncPasses(t, () => assertions.throwsAsync(Promise.reject('foo'), {any: true}));
throwsAsyncPasses(t, () => assertions.throwsAsync(Promise.reject('foo'), {any: true})); // eslint-disable-line prefer-promise-reject-errors

// Passes because the function returned a promise rejected with an error.
throwsAsyncPasses(t, () => assertions.throwsAsync(() => Promise.reject(new Error())));
Expand Down