2023-02-05 23:52:47 +01:00
|
|
|
import { jest } from '@jest/globals'
|
2023-08-16 13:43:54 +02:00
|
|
|
import '@testing-library/jest-dom'
|
2022-11-16 00:14:59 +01:00
|
|
|
import 'jest-canvas-mock'
|
|
|
|
import giphy from './__fixtures__/giphy.json'
|
2023-02-05 23:52:47 +01:00
|
|
|
import { dataLocation } from './__fixtures__/location'
|
2022-11-16 00:14:59 +01:00
|
|
|
import './__mocks__/matchMedia'
|
|
|
|
|
|
|
|
jest.mock('next/router', () => ({
|
|
|
|
useRouter: jest.fn().mockImplementation(() => ({
|
|
|
|
route: '/',
|
2022-11-17 19:07:54 +01:00
|
|
|
pathname: '/'
|
2022-11-16 00:14:59 +01:00
|
|
|
}))
|
|
|
|
}))
|
|
|
|
|
|
|
|
jest.mock('next/head', () => {
|
|
|
|
return {
|
|
|
|
__esModule: true,
|
|
|
|
default: ({ children }: { children: Array<React.ReactElement> }) => {
|
|
|
|
return <>{children}</>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-11-17 21:58:40 +01:00
|
|
|
jest.mock('../src/hooks/useLocation', () => ({
|
|
|
|
useLocation: jest.fn().mockImplementation(() => dataLocation)
|
|
|
|
}))
|
|
|
|
|
2022-11-16 00:14:59 +01:00
|
|
|
jest.mock('@giphy/js-fetch-api', () => ({
|
|
|
|
GiphyFetch: jest.fn().mockImplementation(() => ({
|
|
|
|
random: jest.fn().mockImplementation(() => Promise.resolve(giphy))
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
|
|
|
|
const unmockedFetch = global.fetch
|
2022-11-17 21:58:40 +01:00
|
|
|
const unmockedEnv = process.env
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
// jest.resetModules()
|
|
|
|
global.fetch = unmockedFetch
|
|
|
|
process.env = { ...unmockedEnv }
|
|
|
|
})
|
2022-11-16 00:14:59 +01:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
global.fetch = unmockedFetch
|
2022-11-17 21:58:40 +01:00
|
|
|
process.env = unmockedEnv
|
2023-06-18 16:24:41 +02:00
|
|
|
// jest.restoreAllMocks()
|
2022-11-16 00:14:59 +01:00
|
|
|
})
|