-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support AssertionError expected and actual values #3217
Changes from 2 commits
a4dc6bd
d413b63
90497d5
ba9e4b5
0acdaf7
8969ed8
cc43225
4332df0
f6d7126
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
* @emails oncall+jsinfra | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const assert = require('assert'); | ||
|
||
test('assert', () => { | ||
assert(false); | ||
}); | ||
|
||
test('assert with a message', () => { | ||
assert(false, 'this is a message'); | ||
}); | ||
|
||
test('assert.ok', () => { | ||
assert.ok(false); | ||
}); | ||
|
||
test('assert.ok with a message', () => { | ||
assert.ok(false, 'this is a message'); | ||
}); | ||
|
||
test('assert.equal', () => { | ||
assert.equal(1, 2); | ||
}); | ||
|
||
test('assert.equal with a message', () => { | ||
assert.equal(1, 2, 'this is a message'); | ||
}); | ||
|
||
test('assert.deepEqual', () => { | ||
assert.deepEqual({a: {b: {c: 5}}}, {a: {b: {c: 6}}}); | ||
}); | ||
|
||
test('assert.deepEqual with a message', () => { | ||
assert.deepEqual({a: {b: {c: 5}}}, {a: {b: {c: 7}}}, 'this is a message'); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
/* eslint-disable sort-keys */ | ||
'use strict'; | ||
|
||
const diff = require('jest-diff'); | ||
const { | ||
matcherHint, | ||
printReceived, | ||
printExpected, | ||
} = require('jest-matcher-utils'); | ||
const ExpectationFailed = require('../ExpectationFailed'); | ||
const expectationResultFactory = require('../expectationResultFactory'); | ||
|
||
|
@@ -121,10 +127,26 @@ Spec.prototype.onException = function onException(e) { | |
return; | ||
} | ||
|
||
const {expected, actual} = e || {}; | ||
let message; | ||
if (expected && actual) { | ||
const diffString = diff(expected, actual, { | ||
expand: this.expand, | ||
}); | ||
message = matcherHint('.toBe') + | ||
'\n\n' + | ||
`Expected value to be (using ===):\n` + | ||
` ${printExpected(expected)}\n` + | ||
`Received:\n` + | ||
` ${printReceived(actual)}` + | ||
(diffString ? `\n\nDifference:\n\n${diffString}` : ''); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any way we can make the call to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried that earlier and the process just hung forever which I thought was odd... |
||
|
||
this.addExpectationResult( | ||
false, | ||
{ | ||
matcherName: '', | ||
matcherName: 'blah', | ||
message, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've verified that adding this property (even when it's |
||
passed: false, | ||
expected: '', | ||
actual: '', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like
toBe
is probably the wrong thing to use for the matcher hint... 🤔