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

39 lines
956 B
TypeScript
Raw Permalink Normal View History

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'
2024-02-06 02:06:58 +01:00
import fetchMock from 'jest-fetch-mock'
2024-02-05 16:57:24 +01:00
import giphyMock from './__fixtures__/giphy.json'
2023-02-05 23:52:47 +01:00
import { dataLocation } from './__fixtures__/location'
import './__mocks__/matchMedia'
2024-02-06 02:06:58 +01:00
fetchMock.enableMocks()
jest.mock('next/navigation', () => ({
usePathname: jest.fn().mockImplementationOnce(() => '/')
}))
2024-02-06 02:06:58 +01:00
jest.mock('../src/lib/getLocation', () => ({
getLocation: jest.fn().mockImplementation(() => dataLocation),
2024-02-05 16:57:24 +01:00
preloadLocation: jest.fn()
}))
2024-02-06 02:06:58 +01:00
jest.mock('../src/lib/getRandomGif', () => ({
getRandomGif: jest
.fn()
2024-02-05 16:57:24 +01:00
.mockImplementation(() => giphyMock.data.images.original.mp4)
}))
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
jest.restoreAllMocks()
})