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

41 lines
1.0 KiB
TypeScript
Raw 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-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 reposMock from './__fixtures__/repos.json'
import './__mocks__/matchMedia'
jest.mock('next/navigation', () => ({
usePathname: jest.fn().mockImplementationOnce(() => '/')
}))
2024-02-05 16:57:24 +01:00
jest.mock('../src/actions/getLocation', () => ({
getLocation: jest.fn().mockImplementation(() => dataLocation),
2024-02-05 16:57:24 +01:00
preloadLocation: jest.fn()
}))
jest.mock('../src/actions/getRandomGif', () => ({
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
}))
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()
})