1
0
mirror of https://github.com/kremalicious/portfolio.git synced 2024-12-22 17:23:22 +01:00
portfolio/tests/jest.setup.tsx
2022-11-17 20:58:40 +00:00

50 lines
1.2 KiB
TypeScript

import '@testing-library/jest-dom/extend-expect'
import 'jest-canvas-mock'
import { jest } from '@jest/globals'
import { useLocation } from '../src/hooks/useLocation'
import framer from 'framer-motion'
import { dataLocation } from './__fixtures__/location'
import giphy from './__fixtures__/giphy.json'
import './__mocks__/matchMedia'
jest.mock('next/router', () => ({
useRouter: jest.fn().mockImplementation(() => ({
route: '/',
pathname: '/'
}))
}))
jest.mock('next/head', () => {
return {
__esModule: true,
default: ({ children }: { children: Array<React.ReactElement> }) => {
return <>{children}</>
}
}
})
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
const unmockedEnv = process.env
beforeEach(() => {
// jest.resetModules()
global.fetch = unmockedFetch
process.env = { ...unmockedEnv }
})
afterEach(() => {
global.fetch = unmockedFetch
process.env = unmockedEnv
jest.restoreAllMocks()
})