Skip to content

Commit

Permalink
WIP: getting close to a working version
Browse files Browse the repository at this point in the history
  • Loading branch information
Kent C. Dodds committed Mar 29, 2017
1 parent a4dc6bd commit d413b63
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 31 deletions.
98 changes: 68 additions & 30 deletions integration_tests/__tests__/__snapshots__/failures-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@ Object {
"rest": " FAIL __tests__/assertion-count-test.js
● .assertions() › throws
expect(received).toBeTruthy()
Expected value to be truthy, instead received
false
Error
Error: expect(received).toBeTruthy()
at Object.throws (__tests__/assertion-count-test.js:14:17)
Expected value to be truthy, instead received
false
● .assertions() › throws
Expand All @@ -74,12 +73,11 @@ Object {
● .assertions() › throws on redeclare of assertion count
expect(received).toBeTruthy()
Expected value to be truthy, instead received
false
Error
Error: expect(received).toBeTruthy()
at Object.redeclare (__tests__/assertion-count-test.js:18:17)
Expected value to be truthy, instead received
false
● .assertions() › throws on assertion
Expand Down Expand Up @@ -109,51 +107,91 @@ Object {
"rest": " FAIL __tests__/node-assertion-error-test.js
assert
AssertionError: false == true
at Object.test (__tests__/node-assertion-error-test.js:16:3)
Error
AssertionError: false == true
assert with a message
AssertionError: this is a message
at Object.test (__tests__/node-assertion-error-test.js:20:3)
Error
AssertionError: this is a message
assert.ok
AssertionError: false == true
at Object.test (__tests__/node-assertion-error-test.js:24:10)
Error
AssertionError: false == true
assert.ok with a message
AssertionError: this is a message
at Object.test (__tests__/node-assertion-error-test.js:28:10)
Error
AssertionError: this is a message
assert.equal
AssertionError: 1 == 2
Error
expect(received).toBe(expected)
at Object.test (__tests__/node-assertion-error-test.js:32:10)
Expected value to be (using ===):
2
Received:
1
assert.equal with a message
AssertionError: this is a message
Error
expect(received).toBe(expected)
at Object.test (__tests__/node-assertion-error-test.js:36:10)
Expected value to be (using ===):
2
Received:
1
assert.deepEqual
AssertionError: { a: { b: { c: 5 } } } deepEqual { a: { b: { c: 6 } } }
Error
expect(received).toBe(expected)
Expected value to be (using ===):
{\\"a\\": {\\"b\\": {\\"c\\": 6}}}
Received:
{\\"a\\": {\\"b\\": {\\"c\\": 5}}}
Difference:
at Object.test (__tests__/node-assertion-error-test.js:40:10)
- Expected
+ Received
Object {
\\"a\\": Object {
\\"b\\": Object {
- \\"c\\": 6,
+ \\"c\\": 5,
},
},
}
assert.deepEqual with a message
AssertionError: this is a message
Error
expect(received).toBe(expected)
Expected value to be (using ===):
{\\"a\\": {\\"b\\": {\\"c\\": 7}}}
Received:
{\\"a\\": {\\"b\\": {\\"c\\": 5}}}
Difference:
- Expected
+ Received
at Object.test (__tests__/node-assertion-error-test.js:44:10)
Object {
\\"a\\": Object {
\\"b\\": Object {
- \\"c\\": 7,
+ \\"c\\": 5,
},
},
}
assert
assert with a message
Expand Down
1 change: 1 addition & 0 deletions packages/jest-jasmine2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 23 additions & 1 deletion packages/jest-jasmine2/src/jasmine/Spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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: '',
Expand Down

0 comments on commit d413b63

Please sign in to comment.