diff --git a/packages/jest-jasmine2/package.json b/packages/jest-jasmine2/package.json index a4220b2f6ea2..b215c928a86c 100644 --- a/packages/jest-jasmine2/package.json +++ b/packages/jest-jasmine2/package.json @@ -9,6 +9,7 @@ "main": "build/index.js", "dependencies": { "graceful-fs": "^4.1.11", + "jest-diff": "^19.0.0", "jest-matcher-utils": "^19.0.0", "jest-matchers": "^19.0.0", "jest-message-util": "^19.0.0", diff --git a/packages/jest-jasmine2/src/jasmine/Spec.js b/packages/jest-jasmine2/src/jasmine/Spec.js index e9403e869547..b70f45767ea6 100644 --- a/packages/jest-jasmine2/src/jasmine/Spec.js +++ b/packages/jest-jasmine2/src/jasmine/Spec.js @@ -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}` : ''); + } + this.addExpectationResult( false, { - matcherName: '', + matcherName: 'blah', + message, passed: false, expected: '', actual: '',