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-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'
|
2024-02-04 23:09:00 +01:00
|
|
|
import reposMock from './__fixtures__/repos.json'
|
2022-11-16 00:14:59 +01:00
|
|
|
import './__mocks__/matchMedia'
|
|
|
|
|
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-05 16:57:24 +01:00
|
|
|
jest.mock('../src/actions/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()
|
|
|
|
}))
|
|
|
|
|
|
|
|
jest.mock('../src/actions/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)
|
|
|
|
}))
|
|
|
|
|
|
|
|
jest.mock('../src/actions/getRepos', () => ({
|
|
|
|
getRepos: jest.fn().mockImplementation(() => reposMock)
|
2022-11-17 21:58:40 +01:00
|
|
|
}))
|
|
|
|
|
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
|
|
|
})
|