-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Improve chai support (with detailed output, to match jest exceptions) #8454
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
Merged
jeysal
merged 13 commits into
jestjs:master
from
rpgeeganage:improve_chai_assertion_messages_display
May 17, 2019
Merged
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3c3a721
added fix to improve chai output
rpgeeganage c4ba682
fix linting issue
rpgeeganage bfd6e62
update the change log
rpgeeganage f9ddff7
fix changelog lint
rpgeeganage 5772bd3
added extra check to see error is not undefined
rpgeeganage db0eead
fixed the comments
rpgeeganage 243ba85
fix tsc issue
rpgeeganage e568d07
fix the incorrect test case
rpgeeganage 0764ed4
remove assert.(a,b) message if operator not set
rpgeeganage 821a795
remove assert.(a,b) message if operator not set
rpgeeganage 69d3778
fix assert message
rpgeeganage 173e9c6
fix linting
rpgeeganage de3815f
removed unwanted empty string in final message
rpgeeganage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
|
||
| exports[`chai assertion errors should display properly 1`] = ` | ||
| FAIL __tests__/chai_assertion.js | ||
| ● chai.js assertion library test › expect | ||
|
|
||
| assert.(received, expected) | ||
|
|
||
| Expected value "hello sunshine" | ||
| Received: | ||
| "hello world" | ||
|
|
||
| Message: | ||
| expected 'hello world' to equal 'hello sunshine' | ||
|
|
||
| Difference: | ||
|
|
||
| - Expected | ||
| + Received | ||
|
|
||
| - hello sunshine | ||
| + hello world | ||
|
|
||
| 11 | describe('chai.js assertion library test', () => { | ||
| 12 | it('expect', () => { | ||
| > 13 | chai.expect('hello world').to.equal('hello sunshine'); | ||
| | ^ | ||
| 14 | }); | ||
| 15 | | ||
| 16 | it('should', () => { | ||
|
|
||
| at Object.equal (__tests__/chai_assertion.js:13:35) | ||
|
|
||
| ● chai.js assertion library test › should | ||
|
|
||
| assert.(received, expected) | ||
|
|
||
| Expected value "hello sunshine" | ||
| Received: | ||
| "hello world" | ||
|
|
||
| Message: | ||
| expected 'hello world' to equal 'hello sunshine' | ||
|
|
||
| Difference: | ||
|
|
||
| - Expected | ||
| + Received | ||
|
|
||
| - hello sunshine | ||
| + hello world | ||
|
|
||
| 18 | const stringExpected = 'hello world'; | ||
| 19 | const actualExpected = 'hello sunshine'; | ||
| > 20 | stringExpected.should.to.equal(actualExpected); | ||
| | ^ | ||
| 21 | }); | ||
| 22 | | ||
| 23 | it('assert', () => { | ||
|
|
||
| at Object.equal (__tests__/chai_assertion.js:20:30) | ||
|
|
||
| ● chai.js assertion library test › assert | ||
|
|
||
| assert.(received, expected) | ||
|
|
||
| Expected value "hello sunshine" | ||
| Received: | ||
| "hello world" | ||
|
|
||
| Message: | ||
| expected 'hello world' to equal 'hello sunshine' | ||
|
|
||
| Difference: | ||
|
|
||
| - Expected | ||
| + Received | ||
|
|
||
| - hello sunshine | ||
| + hello world | ||
|
|
||
| 22 | | ||
| 23 | it('assert', () => { | ||
| > 24 | chai.assert.strictEqual('hello world', 'hello sunshine'); | ||
| | ^ | ||
| 25 | }); | ||
| 26 | }); | ||
| 27 | | ||
|
|
||
| at Object.strictEqual (__tests__/chai_assertion.js:24:17) | ||
| `; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| import path from 'path'; | ||
| import {wrap} from 'jest-snapshot-serializer-raw'; | ||
| import runJest from '../runJest'; | ||
| import {extractSummary, run} from '../Utils'; | ||
|
|
||
| test('chai assertion errors should display properly', () => { | ||
| const dir = path.resolve(__dirname, '../chai-assertion-library-errors'); | ||
| run('yarn', dir); | ||
|
|
||
| const {stderr} = runJest('chai-assertion-library-errors'); | ||
| const {rest} = extractSummary(stderr); | ||
| expect(wrap(rest)).toMatchSnapshot(); | ||
| }); |
26 changes: 26 additions & 0 deletions
26
e2e/chai-assertion-library-errors/__tests__/chai_assertion.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /** | ||
| * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| 'use strict'; | ||
| const chai = require('chai'); | ||
|
|
||
| describe('chai.js assertion library test', () => { | ||
| it('expect', () => { | ||
| chai.expect('hello world').to.equal('hello sunshine'); | ||
| }); | ||
|
|
||
| it('should', () => { | ||
| chai.should(); | ||
| const stringExpected = 'hello world'; | ||
| const actualExpected = 'hello sunshine'; | ||
| stringExpected.should.to.equal(actualExpected); | ||
|
rpgeeganage marked this conversation as resolved.
Outdated
|
||
| }); | ||
|
|
||
| it('assert', () => { | ||
| chai.assert.strictEqual('hello world', 'hello sunshine'); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "jest": { | ||
| "testEnvironment": "node", | ||
| "verbose": false | ||
| }, | ||
| "dependencies": { | ||
| "chai": "^4.2.0" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
| # yarn lockfile v1 | ||
|
|
||
|
|
||
| assertion-error@^1.1.0: | ||
| version "1.1.0" | ||
| resolved "https://registry.yarnpkg.com/assertion-error/-/assertion-error-1.1.0.tgz#e60b6b0e8f301bd97e5375215bda406c85118c0b" | ||
| integrity sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw== | ||
|
|
||
| chai@^4.2.0: | ||
| version "4.2.0" | ||
| resolved "https://registry.yarnpkg.com/chai/-/chai-4.2.0.tgz#760aa72cf20e3795e84b12877ce0e83737aa29e5" | ||
| integrity sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw== | ||
| dependencies: | ||
| assertion-error "^1.1.0" | ||
| check-error "^1.0.2" | ||
| deep-eql "^3.0.1" | ||
| get-func-name "^2.0.0" | ||
| pathval "^1.1.0" | ||
| type-detect "^4.0.5" | ||
|
|
||
| check-error@^1.0.2: | ||
| version "1.0.2" | ||
| resolved "https://registry.yarnpkg.com/check-error/-/check-error-1.0.2.tgz#574d312edd88bb5dd8912e9286dd6c0aed4aac82" | ||
| integrity sha1-V00xLt2Iu13YkS6Sht1sCu1KrII= | ||
|
|
||
| deep-eql@^3.0.1: | ||
| version "3.0.1" | ||
| resolved "https://registry.yarnpkg.com/deep-eql/-/deep-eql-3.0.1.tgz#dfc9404400ad1c8fe023e7da1df1c147c4b444df" | ||
| integrity sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw== | ||
| dependencies: | ||
| type-detect "^4.0.0" | ||
|
|
||
| get-func-name@^2.0.0: | ||
| version "2.0.0" | ||
| resolved "https://registry.yarnpkg.com/get-func-name/-/get-func-name-2.0.0.tgz#ead774abee72e20409433a066366023dd6887a41" | ||
| integrity sha1-6td0q+5y4gQJQzoGY2YCPdaIekE= | ||
|
|
||
| pathval@^1.1.0: | ||
| version "1.1.0" | ||
| resolved "https://registry.yarnpkg.com/pathval/-/pathval-1.1.0.tgz#b942e6d4bde653005ef6b71361def8727d0645e0" | ||
| integrity sha1-uULm1L3mUwBe9rcTYd74cn0GReA= | ||
|
|
||
| type-detect@^4.0.0, type-detect@^4.0.5: | ||
| version "4.0.8" | ||
| resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.8.tgz#7646fb5f18871cfbb7749e69bd39a6388eb7450c" | ||
| integrity sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.