1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-23 01:29:41 +01:00
portfolio/tests/jest.setup.tsx

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-02-05 23:52:47 +01:00
import { jest } from '@jest/globals'
import '@testing-library/jest-dom/extend-expect'
import 'jest-canvas-mock'
import giphy from './__fixtures__/giphy.json'
2023-02-05 23:52:47 +01:00
import { dataLocation } from './__fixtures__/location'
import './__mocks__/matchMedia'
jest.mock('next/router', () => ({
useRouter: jest.fn().mockImplementation(() => ({
route: '/',
2022-11-17 19:07:54 +01:00
pathname: '/'
}))
}))
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)
}))
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 }
})
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()
})