Skip to content

Commit

Permalink
Param to skip test names when specified (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
lws803 authored Aug 24, 2022
1 parent 7638dae commit f716c48
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ failOnConsole({
})
```
### skipTestNames
Use this if you want to ignore checks introduced by this library for specific test names.
```ts
failOnConsole({
skipTestNames: ['TEST_NAME'],
})
```
## License
[MIT](https://github.com/ValentinH/jest-fail-on-console/blob/master/LICENSE)
Expand Down
5 changes: 5 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ declare namespace init {
message: string,
methodName: 'assert' | 'debug' | 'error' | 'info' | 'log' | 'warn'
) => boolean

/**
* This parameter lets you define a list of test names to skip console checks for.
*/
skipTestNames?: string[]
}
}

Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const init = ({
shouldFailOnInfo = false,
shouldFailOnLog = false,
shouldFailOnWarn = true,
skipTestNames = [],
silenceMessage,
} = {}) => {
const flushUnexpectedConsoleCalls = (methodName, unexpectedConsoleCallStacks) => {
Expand Down Expand Up @@ -71,11 +72,13 @@ const init = ({
let originalMethod = console[methodName]

beforeEach(() => {
if (skipTestNames.includes(expect.getState().currentTestName)) return
console[methodName] = newMethod // eslint-disable-line no-console
unexpectedConsoleCallStacks.length = 0
})

afterEach(() => {
if (skipTestNames.includes(expect.getState().currentTestName)) return
flushUnexpectedConsoleCalls(methodName, unexpectedConsoleCallStacks)
console[methodName] = originalMethod
})
Expand Down

0 comments on commit f716c48

Please sign in to comment.