From ff80d4aae96957ff3b679b07395f77f04f7b1bfc Mon Sep 17 00:00:00 2001 From: lws803 Date: Wed, 24 Aug 2022 16:49:10 +0800 Subject: [PATCH 1/4] added override based on test name --- index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.js b/index.js index 853ed2a..155f8ed 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,7 @@ const init = ({ shouldFailOnInfo = false, shouldFailOnLog = false, shouldFailOnWarn = true, + skipTestNames = [], silenceMessage, } = {}) => { const flushUnexpectedConsoleCalls = (methodName, unexpectedConsoleCallStacks) => { @@ -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 }) From acaf892cdd4d7cd841750fc8710641ced9757886 Mon Sep 17 00:00:00 2001 From: lws803 Date: Wed, 24 Aug 2022 16:54:54 +0800 Subject: [PATCH 2/4] updated README --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 943c3ad..ea922e9 100644 --- a/README.md +++ b/README.md @@ -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) From 60624af26bcf32b8e682fcaaeb6044d482911bbd Mon Sep 17 00:00:00 2001 From: lws803 Date: Wed, 24 Aug 2022 17:30:05 +0800 Subject: [PATCH 3/4] added param in index.d.ts --- index.d.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/index.d.ts b/index.d.ts index 5fd8c04..b7b6b4c 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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?: [] } } From cc2bdc4485ab79273d4d88ac253e3e72f0f6adf3 Mon Sep 17 00:00:00 2001 From: lws803 Date: Wed, 24 Aug 2022 17:38:24 +0800 Subject: [PATCH 4/4] string array --- index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index b7b6b4c..5498a57 100644 --- a/index.d.ts +++ b/index.d.ts @@ -41,7 +41,7 @@ declare namespace init { /** * This parameter lets you define a list of test names to skip console checks for. */ - skipTestNames?: [] + skipTestNames?: string[] } }