From 59aee75529e4a27789f1ea26648daac37cc191cf Mon Sep 17 00:00:00 2001 From: Do Trung Kien Date: Fri, 28 Jun 2019 13:36:25 +0700 Subject: [PATCH] use AssertionError instead assert.fail, add message confirmation to assertFailure --- src/expectRevert.js | 8 ++++++-- test/helpers/assertFailure.js | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/expectRevert.js b/src/expectRevert.js index d33d0aa..2dcc0f6 100644 --- a/src/expectRevert.js +++ b/src/expectRevert.js @@ -2,7 +2,7 @@ const { web3 } = require('./setup'); const colors = require('ansi-colors'); const semver = require('semver'); -const assert = require('assert'); +const AssertionError = require('assert').AssertionError; async function expectException (promise, expectedError) { try { @@ -10,7 +10,11 @@ async function expectException (promise, expectedError) { } catch (error) { if (error.message.indexOf(expectedError) === -1) { const actualError = error.message.replace('Returned error: VM Exception while processing transaction: ', ''); - assert.fail(`Wrong failure type, expected '${expectedError}' and got '${actualError}'`); + throw new AssertionError({ + message: 'Wrong failure type', + expected: expectedError, + actual: actualError + }); } return; } diff --git a/test/helpers/assertFailure.js b/test/helpers/assertFailure.js index f5a63c4..b220954 100644 --- a/test/helpers/assertFailure.js +++ b/test/helpers/assertFailure.js @@ -1,9 +1,13 @@ const { expect } = require('chai'); +const AssertionError = require('assert').AssertionError; async function assertFailure (promise) { try { await promise; } catch (error) { + if (error instanceof AssertionError) { + expect(error.message).to.equal('Wrong failure type'); + } return; } expect.fail();