-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publish new package
@adeira/jest-disallow-console
This is a followup after jestjs/jest#11456. Basically, our previous solution stopped working reliably and after a discussion with Jest team I realized that it's an ugly hack and we are lucky it worked for so long. This change introduces a new `@adeira/jest-disallow-console` package which helps with testing console warnings. The code is heavily inspired by `warnings.js` from `facebook/relay` (see: https://github.com/facebook/relay/blob/57dde664137a221a4633d1c02592b2a4e17d3feb/packages/relay-test-utils-internal/warnings.js) but it's modified to work with `global.console` instead of `warning` module.
- Loading branch information
Showing
17 changed files
with
205 additions
and
114 deletions.
There are no files selected for viewing
This file contains 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 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
5 changes: 4 additions & 1 deletion
5
src/example-relay/src/Homepage/locations/__tests__/LocationsPaginatedRefetch.test.js
This file contains 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 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 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 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 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 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 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,3 @@ | ||
__tests__ | ||
BUILD.bazel | ||
BUILD |
This file contains 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,22 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019-present, Adeira | ||
Copyright (c) 2013-present, Facebook, Inc. | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains 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 @@ | ||
TKTK |
This file contains 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,24 @@ | ||
// @flow strict | ||
|
||
import { disallowWarnings, expectWarningWillFire, expectToWarn } from '../index'; | ||
|
||
disallowWarnings(); | ||
|
||
// eslint-disable-next-line jest/prefer-todo | ||
it('should pass when there are no warnings', () => { | ||
// no warnings here | ||
}); | ||
|
||
it('should pass when all warnings are expected (`expectWarningWillFire`)', () => { | ||
expectWarningWillFire('yadada 1'); | ||
expectWarningWillFire('yadada 2'); | ||
|
||
console.warn('yadada 1'); // eslint-disable-line no-console | ||
console.warn('yadada 2'); // eslint-disable-line no-console | ||
}); | ||
|
||
it('should pass when all warnings are expected (`expectToWarn`)', () => { | ||
expectToWarn('yadada', () => { | ||
console.warn('yadada'); // eslint-disable-line no-console | ||
}); | ||
}); |
This file contains 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,19 @@ | ||
// @flow strict | ||
|
||
import { expectToWarn, expectWarningWillFire } from '../index'; | ||
|
||
it('throws an error when `expectToWarn` are nested', () => { | ||
expect(() => { | ||
expectToWarn('aaa', () => { | ||
expectToWarn('bbb', () => {}); | ||
}); | ||
}).toThrowErrorMatchingInlineSnapshot(`"Cannot nest \`expectToWarn()\` calls."`); | ||
}); | ||
|
||
it('throws an error when `expectWarningWillFire` is called without `disallowWarnings`', () => { | ||
expect(() => { | ||
expectWarningWillFire('aaa'); | ||
}).toThrowErrorMatchingInlineSnapshot( | ||
`"\`disallowWarnings\` needs to be called before \`expectWarningWillFire\`"`, | ||
); | ||
}); |
Oops, something went wrong.