-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: don't patch console.error for pure imports
Added RHTL_DISABLE_ERROR_FILTERING environment variable toggle to globally disable console filtering. Fixes #546
- Loading branch information
Showing
11 changed files
with
145 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
process.env.RHTL_DISABLE_ERROR_FILTERING = true |
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,39 @@ | ||
import { renderHook } from '..' | ||
|
||
describe('error output suppression (disabled) tests', () => { | ||
function useError(throwError?: boolean) { | ||
if (throwError) { | ||
throw new Error('expected') | ||
} | ||
return true | ||
} | ||
|
||
const originalConsoleError = console.error | ||
const mockConsoleError = jest.fn() | ||
|
||
beforeAll(() => { | ||
process.env.RHTL_DISABLE_ERROR_FILTERING = 'true' | ||
}) | ||
|
||
beforeEach(() => { | ||
console.error = mockConsoleError | ||
}) | ||
|
||
afterEach(() => { | ||
console.error = originalConsoleError | ||
}) | ||
|
||
test('should not suppress error output', () => { | ||
const { result } = renderHook(() => useError(true)) | ||
|
||
expect(result.error).toEqual(Error('expected')) | ||
expect(mockConsoleError).toBeCalledWith( | ||
expect.stringMatching(/^Error: Uncaught \[Error: expected\]/), | ||
expect.any(Error) | ||
) | ||
expect(mockConsoleError).toBeCalledWith( | ||
expect.stringMatching(/^The above error occurred in the <TestComponent> component:/) | ||
) | ||
expect(mockConsoleError).toBeCalledTimes(2) | ||
}) | ||
}) |
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,35 @@ | ||
import { renderHook } from '../pure' | ||
|
||
describe('error output suppression (pure) tests', () => { | ||
function useError(throwError?: boolean) { | ||
if (throwError) { | ||
throw new Error('expected') | ||
} | ||
return true | ||
} | ||
|
||
const originalConsoleError = console.error | ||
const mockConsoleError = jest.fn() | ||
|
||
beforeEach(() => { | ||
console.error = mockConsoleError | ||
}) | ||
|
||
afterEach(() => { | ||
console.error = originalConsoleError | ||
}) | ||
|
||
test('should not suppress error output', () => { | ||
const { result } = renderHook(() => useError(true)) | ||
|
||
expect(result.error).toEqual(Error('expected')) | ||
expect(mockConsoleError).toBeCalledWith( | ||
expect.stringMatching(/^Error: Uncaught \[Error: expected\]/), | ||
expect.any(Error) | ||
) | ||
expect(mockConsoleError).toBeCalledWith( | ||
expect.stringMatching(/^The above error occurred in the <TestComponent> component:/) | ||
) | ||
expect(mockConsoleError).toBeCalledTimes(2) | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { autoRegisterCleanup } from '../core/cleanup' | ||
import { enableErrorOutputSuppression } from '../helpers/console' | ||
|
||
autoRegisterCleanup() | ||
enableErrorOutputSuppression() | ||
|
||
export * from './pure' |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { autoRegisterCleanup } from './core/cleanup' | ||
import { enableErrorOutputSuppression } from './helpers/console' | ||
|
||
autoRegisterCleanup() | ||
enableErrorOutputSuppression() | ||
|
||
export * from './pure' |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { autoRegisterCleanup } from '../core/cleanup' | ||
import { enableErrorOutputSuppression } from '../helpers/console' | ||
|
||
autoRegisterCleanup() | ||
enableErrorOutputSuppression() | ||
|
||
export * from './pure' |
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import { autoRegisterCleanup } from '../core/cleanup' | ||
import { enableErrorOutputSuppression } from '../helpers/console' | ||
|
||
autoRegisterCleanup() | ||
enableErrorOutputSuppression() | ||
|
||
export * from './pure' |