-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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 8 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 |
---|---|---|
|
@@ -103,3 +103,272 @@ Ran all test suites matching \\"assertion-count-test.js\\". | |
", | ||
} | ||
`; | ||
|
||
exports[`works with node assert 1`] = ` | ||
Object { | ||
"rest": " FAIL __tests__/node-assertion-error-test.js | ||
● assert | ||
|
||
assert.equal(received, expected) or assert(received) | ||
|
||
Expected value to be (operator: ==): | ||
true | ||
Received: | ||
false | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:16:3) | ||
|
||
● assert with a message | ||
|
||
assert.equal(received, expected) or assert(received) | ||
|
||
Expected value to be (operator: ==): | ||
true | ||
Received: | ||
false | ||
|
||
Message: | ||
this is a message | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:20:3) | ||
|
||
● assert.ok | ||
|
||
assert.equal(received, expected) or assert(received) | ||
|
||
Expected value to be (operator: ==): | ||
true | ||
Received: | ||
false | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:24:10) | ||
|
||
● assert.ok with a message | ||
|
||
assert.equal(received, expected) or assert(received) | ||
|
||
Expected value to be (operator: ==): | ||
true | ||
Received: | ||
false | ||
|
||
Message: | ||
this is a message | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:28:10) | ||
|
||
● assert.equal | ||
|
||
assert.equal(received, expected) or assert(received) | ||
|
||
Expected value to be (operator: ==): | ||
2 | ||
Received: | ||
1 | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:32:10) | ||
|
||
● assert.notEqual | ||
|
||
assert.notEqual(received, expected) | ||
|
||
Expected value not to be (operator: !=): | ||
1 | ||
Received: | ||
1 | ||
|
||
Difference: | ||
|
||
Compared values have no visual difference. | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:36:10) | ||
|
||
● assert.deepEqual | ||
|
||
assert.deepEqual(received, expected) | ||
|
||
Expected value to deepEqual to: | ||
{\\"a\\": {\\"b\\": {\\"c\\": 6}}} | ||
Received: | ||
{\\"a\\": {\\"b\\": {\\"c\\": 5}}} | ||
|
||
Difference: | ||
|
||
- Expected | ||
+ Received | ||
|
||
Object { | ||
\\"a\\": Object { | ||
\\"b\\": Object { | ||
- \\"c\\": 6, | ||
+ \\"c\\": 5, | ||
}, | ||
}, | ||
} | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:40:10) | ||
|
||
● assert.deepEqual with a message | ||
|
||
assert.deepEqual(received, expected) | ||
|
||
Expected value to deepEqual to: | ||
{\\"a\\": {\\"b\\": {\\"c\\": 7}}} | ||
Received: | ||
{\\"a\\": {\\"b\\": {\\"c\\": 5}}} | ||
|
||
Message: | ||
this is a message | ||
|
||
Difference: | ||
|
||
- Expected | ||
+ Received | ||
|
||
Object { | ||
\\"a\\": Object { | ||
\\"b\\": Object { | ||
- \\"c\\": 7, | ||
+ \\"c\\": 5, | ||
}, | ||
}, | ||
} | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:44:10) | ||
|
||
● assert.notDeepEqual | ||
|
||
assert.notDeepEqual(received, expected) | ||
|
||
Expected value to notDeepEqual 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. "not to deeply equal"? |
||
{\\"a\\": 1} | ||
Received: | ||
{\\"a\\": 1} | ||
|
||
Difference: | ||
|
||
Compared values have no visual difference. | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:48:10) | ||
|
||
● assert.strictEqual | ||
|
||
assert.strictEqual(received, expected) | ||
|
||
Expected value to be (operator: ===): | ||
NaN | ||
Received: | ||
1 | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:52:10) | ||
|
||
● assert.notStrictEqual | ||
|
||
assert.notStrictEqual(received, expected) | ||
|
||
Expected value not to be (operator: !==): | ||
1 | ||
Received: | ||
1 | ||
|
||
Message: | ||
My custom error message | ||
|
||
Difference: | ||
|
||
Compared values have no visual difference. | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:56:10) | ||
|
||
● assert.deepStrictEqual | ||
|
||
assert.deepStrictEqual(received, expected) | ||
|
||
Expected value to deepStrictEqual 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. "to deeply and strictly equal"? |
||
{\\"a\\": 2} | ||
Received: | ||
{\\"a\\": 1} | ||
|
||
Difference: | ||
|
||
- Expected | ||
+ Received | ||
|
||
Object { | ||
- \\"a\\": 2, | ||
+ \\"a\\": 1, | ||
} | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:60:10) | ||
|
||
● assert.notDeepStrictEqual | ||
|
||
assert.notDeepStrictEqual(received, expected) | ||
|
||
Expected value to notDeepStrictEqual to: | ||
{\\"a\\": 1} | ||
Received: | ||
{\\"a\\": 1} | ||
|
||
Difference: | ||
|
||
Compared values have no visual difference. | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:64:10) | ||
|
||
● assert.ifError | ||
|
||
Error | ||
1 thrown | ||
|
||
● assert.doesNotThrow | ||
|
||
assert.doesNotThrow(function) | ||
|
||
Expected the function not to throw an error. | ||
Instead, it threw: | ||
[Error: err!] | ||
|
||
Message: | ||
Got unwanted exception.. | ||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:72:10) | ||
|
||
● assert.throws | ||
|
||
assert.throws(function) | ||
|
||
Expected the function to throw an error. | ||
But it didn't throw anything. | ||
|
||
Message: | ||
Missing expected exception.. | ||
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. This is coming from assert, right? 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. Yes, |
||
|
||
at Object.<anonymous> (__tests__/node-assertion-error-test.js:78:10) | ||
|
||
✕ assert | ||
✕ assert with a message | ||
✕ assert.ok | ||
✕ assert.ok with a message | ||
✕ assert.equal | ||
✕ assert.notEqual | ||
✕ assert.deepEqual | ||
✕ assert.deepEqual with a message | ||
✕ assert.notDeepEqual | ||
✕ assert.strictEqual | ||
✕ assert.notStrictEqual | ||
✕ assert.deepStrictEqual | ||
✕ assert.notDeepStrictEqual | ||
✕ assert.ifError | ||
✕ assert.doesNotThrow | ||
✕ assert.throws | ||
|
||
", | ||
"summary": "Test Suites: 1 failed, 1 total | ||
Tests: 16 failed, 16 total | ||
Snapshots: 0 total | ||
Time: <<REPLACED>> | ||
Ran all test suites matching \\"node-assertion-error-test.js\\". | ||
", | ||
} | ||
`; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* 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.notEqual', () => { | ||
assert.notEqual(1, 1); | ||
}); | ||
|
||
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'); | ||
}); | ||
|
||
test('assert.notDeepEqual', () => { | ||
assert.notDeepEqual({a: 1}, {a: 1}); | ||
}); | ||
|
||
test('assert.strictEqual', () => { | ||
assert.strictEqual(1, NaN); | ||
}); | ||
|
||
test('assert.notStrictEqual', () => { | ||
assert.notStrictEqual(1, 1, 'My custom error message'); | ||
}); | ||
|
||
test('assert.deepStrictEqual', () => { | ||
assert.deepStrictEqual({a: 1}, {a: 2}); | ||
}); | ||
|
||
test('assert.notDeepStrictEqual', () => { | ||
assert.notDeepStrictEqual({a: 1}, {a: 1}); | ||
}); | ||
|
||
test('assert.ifError', () => { | ||
assert.ifError(1); | ||
}); | ||
|
||
test('assert.doesNotThrow', () => { | ||
assert.doesNotThrow(() => { | ||
throw Error('err!'); | ||
}); | ||
}); | ||
|
||
test('assert.throws', () => { | ||
assert.throws(() => {}); | ||
}); |
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.
Is this just like ==, but deep? In that case, how about:
"Expected value to deeply equal:"
maybe?