From cf9c6d538a1488c97befb290814ce1593ccd17dd Mon Sep 17 00:00:00 2001 From: Michael Jackson Date: Fri, 6 May 2016 17:18:51 -0700 Subject: [PATCH] Only include diff when objects are not equal --- modules/Expectation.js | 36 ++++++++++++++---------------------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/modules/Expectation.js b/modules/Expectation.js index b6fbc7b..453c7e6 100644 --- a/modules/Expectation.js +++ b/modules/Expectation.js @@ -15,18 +15,6 @@ import { stringContains } from './TestUtils' -const addErrorInfo = (actual, expected, callback) => { - try { - callback() - } catch (error) { - // These attributes are consumed by Mocha to produce a diff output. - error.actual = actual - error.expected = expected - error.showDiff = true - throw error - } -} - /** * An Expectation is a wrapper around an assertion that allows it to be written * in a more natural style, without the need to remember the order of arguments. @@ -85,27 +73,31 @@ class Expectation { } toEqual(value, message) { - addErrorInfo(this.actual, value, () => { + try { assert( isEqual(this.actual, value), (message || 'Expected %s to equal %s'), this.actual, value ) - }) + } catch (error) { + // These attributes are consumed by Mocha to produce a diff output. + error.actual = this.actual + error.expected = value + error.showDiff = true + throw error + } return this } toNotEqual(value, message) { - addErrorInfo(this.actual, value, () => { - assert( - !isEqual(this.actual, value), - (message || 'Expected %s to not equal %s'), - this.actual, - value - ) - }) + assert( + !isEqual(this.actual, value), + (message || 'Expected %s to not equal %s'), + this.actual, + value + ) return this }