-
Notifications
You must be signed in to change notification settings - Fork 0
/
jest.setup.ts
32 lines (24 loc) · 1.19 KB
/
jest.setup.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// jest.setup.js
import '@testing-library/jest-dom/jest-globals'
import 'jest-axe/extend-expect'
import mockRouter from 'next-router-mock'
// @see: https://www.benmvp.com/blog/avoiding-react-act-warning-when-accessibility-testing-next-link-jest-axe/
// In order to run `jest-axe` assertions for components containing
// `next/link`, we need `IntersectionObserver` to always exist,
// but to be mocked so that we can set it to *never* intersect
import 'react-intersection-observer/test-utils'
import { defaultFallbackInView } from 'react-intersection-observer'
import { MockNextNavigation } from './__mocks__/next-navigation'
// `react-intersection-observer/test-utils` will add a mock
// `IntersectionObserver` automatically in every `beforeEach()`.
// But `next/link` checks to see if `IntersectionObserver` exists at module
// scope. So we add the bare minimum to get that check to pass.
global.IntersectionObserver = jest.fn()
// Then, when the tests actually run, we default intersection to
// `false` so that `jest-axe` assertions will pass without needing
// `act()`.
defaultFallbackInView(false)
jest.mock('next/navigation', () => MockNextNavigation)
beforeAll(() => {
mockRouter.setCurrentUrl('/')
})