✅ test(ErrorPage): suppress expected console errors
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { screen, cleanup, render } from '@testing-library/react'
|
import { screen, render } from '@testing-library/react'
|
||||||
import { RouterProvider, createMemoryRouter } from 'react-router-dom'
|
import { RouterProvider, createMemoryRouter } from 'react-router-dom'
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
import { useAnalytics } from 'use-analytics'
|
import { useAnalytics } from 'use-analytics'
|
||||||
@@ -10,19 +10,14 @@ vi.mock('use-analytics', () => ({
|
|||||||
useAnalytics: () => ({ plugins: { enable: vi.fn(), disable: vi.fn() } }),
|
useAnalytics: () => ({ plugins: { enable: vi.fn(), disable: vi.fn() } }),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
// Tests
|
// Suppress console.error messages during tests
|
||||||
describe('Renders ErrorPage correctly', async () => {
|
const originalConsoleError = console.error
|
||||||
/**
|
console.error = vi.fn()
|
||||||
* Resets all renders after each test
|
|
||||||
*/
|
|
||||||
afterEach(() => {
|
|
||||||
cleanup()
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
describe('Renders ErrorPage correctly', async () => {
|
||||||
* Passes - shows title correctly
|
|
||||||
*/
|
|
||||||
it('Should render the error page correctly', () => {
|
it('Should render the error page correctly', () => {
|
||||||
|
console.error = vi.fn()
|
||||||
|
|
||||||
const badRoute = '/some/bad/route'
|
const badRoute = '/some/bad/route'
|
||||||
const router = createMemoryRouter([{ path: '/', element: <div />, errorElement: <ErrorPage /> }], { initialEntries: [badRoute] })
|
const router = createMemoryRouter([{ path: '/', element: <div />, errorElement: <ErrorPage /> }], { initialEntries: [badRoute] })
|
||||||
|
|
||||||
@@ -33,3 +28,5 @@ describe('Renders ErrorPage correctly', async () => {
|
|||||||
expect(screen.getByText(`404 Error: No route matches URL "${badRoute}"`)).toBeInTheDocument()
|
expect(screen.getByText(`404 Error: No route matches URL "${badRoute}"`)).toBeInTheDocument()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
console.error = originalConsoleError
|
||||||
|
|||||||
Reference in New Issue
Block a user