Skip to content

Commit

Permalink
Only include diff when objects are not equal
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed May 7, 2016
1 parent e9396a9 commit cf9c6d5
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions modules/Expectation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit cf9c6d5

Please sign in to comment.