
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
assert-rejects
Advanced tools
Assert that a promise eventually rejects
npm install --save assert-rejects
const assertRejects = require('assert-rejects')
describe('Something', () => {
it('rejects', () => {
const promise = doSomethingThatShouldReject()
return assertRejects(promise)
})
it('rejects with specific code', () => {
const promise = readFileThatDoesntExists()
return assertRejects(promise, err => err.code === 'ENOENT')
})
})
assertRejects(promise[, error][, message])Expects the promise to reject. Returns a new promise that will resolve once the provided promise is resolved.
If specified, error can be a constructor, RegExp, or validation function.
If specified, message will be the message provided by the AssertionError if the promise fails to reject.
Validate instanceof using constructor:
assertRejects(
Promise.reject(new Error('Wrong value')),
Error
)
Validate error message using RegExp:
assertRejects(
Promise.reject(new Error('Wrong value')),
/value/
)
Custom error validation:
assertRejects(
Promise.reject(new Error('Wrong value')),
(err) => ((err instanceof Error) && /value/.test(err)),
'unexpected rejection'
)
Note that error can not be a string. If a string is provided as the second argument, then error is assumed to be omitted and the string will be used for message instead. This can lead to easy-to-miss mistakes:
// THIS IS A MISTAKE! DO NOT DO THIS!
assertRejects(myPromise, 'missing foo', 'did not reject with expected message')
// Do this instead.
assertRejects(myPromise, /missing foo/, 'did not reject with expected message')
FAQs
Assert that a promise eventually rejects
The npm package assert-rejects receives a total of 4,244 weekly downloads. As such, assert-rejects popularity was classified as popular.
We found that assert-rejects demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.