Skip to content
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

Param to skip test names when specified #25

Merged
merged 4 commits into from Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
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
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?: []
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
skipTestNames?: []
skipTestNames?: string[]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops my bad, cc2bdc4 thanks for the suggestion!

}
}

Expand Down
3 changes: 3 additions & 0 deletions index.js
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