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'
|
2022-11-16 00:14:59 +01:00
|
|
|
import './__mocks__/matchMedia'
|
|
|
|
|
2024-02-06 02:06:58 +01:00
|
|
|
fetchMock.enableMocks()
|
|
|
|
|
2024-02-01 19:59:51 +01:00
|
|
|
jest.mock('next/navigation', () => ({
|
|
|
|
usePathname: jest.fn().mockImplementationOnce(() => '/')
|
2022-11-16 00:14:59 +01:00
|
|
|
}))
|
|
|
|
|
2024-02-06 02:06:58 +01:00
|
|
|
jest.mock('../src/lib/getLocation', () => ({
|
2024-02-01 19:59:51 +01:00
|
|
|
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', () => ({
|
2024-02-01 19:59:51 +01:00
|
|
|
getRandomGif: jest
|
|
|
|
.fn()
|
2024-02-05 16:57:24 +01:00
|
|
|
.mockImplementation(() => giphyMock.data.images.original.mp4)
|
|
|
|
}))
|
|
|
|
|
2022-11-16 00:14:59 +01:00
|
|
|
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
|
2024-02-01 19:59:51 +01:00
|
|
|
jest.restoreAllMocks()
|
2022-11-16 00:14:59 +01:00
|
|
|
})
|