test: keep test output clean (#6469)
This commit is contained in:
parent
4d5cc8267e
commit
924e83139b
@ -108,6 +108,7 @@
|
||||
"eslint": "^7.11.0",
|
||||
"eslint-plugin-import": "^2.27",
|
||||
"hardhat": "^2.14.0",
|
||||
"jest-fail-on-console": "^3.1.1",
|
||||
"jest-fetch-mock": "^3.0.3",
|
||||
"jest-styled-components": "^7.0.8",
|
||||
"ms.macro": "^2.0.0",
|
||||
|
@ -3,6 +3,7 @@ import 'jest-styled-components' // adds style diffs to snapshot tests
|
||||
|
||||
import type { createPopper } from '@popperjs/core'
|
||||
import { useWeb3React } from '@web3-react/core'
|
||||
import failOnConsole from 'jest-fail-on-console'
|
||||
import ResizeObserver from 'resize-observer-polyfill'
|
||||
import { Readable } from 'stream'
|
||||
import { mocked } from 'test-utils/mocked'
|
||||
@ -77,3 +78,22 @@ beforeEach(() => {
|
||||
// Mock useWeb3React to return a chainId of 1 by default.
|
||||
mocked(useWeb3React).mockReturnValue({ chainId: 1 } as ReturnType<typeof useWeb3React>)
|
||||
})
|
||||
|
||||
/**
|
||||
* Fail tests if anything is logged to the console. This keeps the console clean and ensures test output stays readable.
|
||||
* If something should log to the console, it should be stubbed and asserted:
|
||||
* @example
|
||||
* beforeEach(() => jest.spyOn(console, 'error').mockReturnsValue())
|
||||
* it('should log an error', () => {
|
||||
* example()
|
||||
* expect(console.error).toHaveBeenCalledWith(expect.any(Error))
|
||||
* })
|
||||
*/
|
||||
failOnConsole({
|
||||
shouldFailOnAssert: true,
|
||||
shouldFailOnDebug: true,
|
||||
shouldFailOnError: true,
|
||||
shouldFailOnInfo: true,
|
||||
shouldFailOnLog: true,
|
||||
shouldFailOnWarn: true,
|
||||
})
|
||||
|
@ -13396,6 +13396,13 @@ jest-environment-node@^26.6.2:
|
||||
jest-mock "^26.6.2"
|
||||
jest-util "^26.6.2"
|
||||
|
||||
jest-fail-on-console@^3.1.1:
|
||||
version "3.1.1"
|
||||
resolved "https://registry.yarnpkg.com/jest-fail-on-console/-/jest-fail-on-console-3.1.1.tgz#4ca0d0cc8f11675e8e9f52159a37a6602a7e6c09"
|
||||
integrity sha512-g9HGhKcWOz8lHeZhLCXGg+RD/7upngiKkkBrHimsO/tGB0qi++QZffOgybjeI2bDW1qgdFiJJEG6t/WeTlfmOw==
|
||||
dependencies:
|
||||
chalk "^4.1.0"
|
||||
|
||||
jest-fetch-mock@^3.0.3:
|
||||
version "3.0.3"
|
||||
resolved "https://registry.yarnpkg.com/jest-fetch-mock/-/jest-fetch-mock-3.0.3.tgz#31749c456ae27b8919d69824f1c2bd85fe0a1f3b"
|
||||
|
Loading…
Reference in New Issue
Block a user