Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Asserting solidity throws in truffle tests.
it('should throw an error', cb => {
const result = aMethodThatRejects()
result.then(x => { cb('Expected error. Instead got ' + x) }))
result.catch(() => cb())

This comment has been minimized.

Copy link
Owner Author

raineorshine commented Mar 16, 2019

In newer versions of node, the originally suggested approach will result in unhandled rejections. They can be suppressed, but a cleaner approach is one of the following:


return aMethodThatRejects().then(
  () => Promise.reject(new Error('Expected method to reject.')),
  err => assert.instanceOf(err, Error)

With Chai:



Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.