mirror of
https://github.com/kremalicious/portfolio.git
synced 2024-12-22 09:13:19 +01:00
test tweaks
This commit is contained in:
parent
cb26018953
commit
93fa06bf1b
@ -1,12 +1,5 @@
|
||||
import { render, screen, act } from '@testing-library/react'
|
||||
import Header from '.'
|
||||
import { dataLocation } from '../../../tests/__fixtures__/location'
|
||||
;(global.fetch as jest.Mock) = jest.fn(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(dataLocation)
|
||||
})
|
||||
)
|
||||
|
||||
describe('Header', () => {
|
||||
it('renders correctly', async () => {
|
||||
|
@ -1,12 +1,5 @@
|
||||
import { render, screen, act } from '@testing-library/react'
|
||||
import Site from '.'
|
||||
import { dataLocation } from '../../../tests/__fixtures__/location'
|
||||
;(global.fetch as jest.Mock) = jest.fn(() =>
|
||||
Promise.resolve({
|
||||
ok: true,
|
||||
json: () => Promise.resolve(dataLocation)
|
||||
})
|
||||
)
|
||||
|
||||
describe('Site', () => {
|
||||
it('renders without crashing', async () => {
|
||||
|
8
src/lib/umami.test.ts
Normal file
8
src/lib/umami.test.ts
Normal file
@ -0,0 +1,8 @@
|
||||
import { UMAMI_SCRIPT_URL, UMAMI_WEBSITE_ID } from './umami'
|
||||
|
||||
describe('lib/umami', () => {
|
||||
test('exports env vars', async () => {
|
||||
expect(UMAMI_SCRIPT_URL).toBe(process.env.NEXT_PUBLIC_UMAMI_SCRIPT_URL)
|
||||
expect(UMAMI_WEBSITE_ID).toBe(process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID)
|
||||
})
|
||||
})
|
@ -1,6 +1,9 @@
|
||||
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'
|
||||
|
||||
@ -20,6 +23,10 @@ jest.mock('next/head', () => {
|
||||
}
|
||||
})
|
||||
|
||||
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))
|
||||
@ -27,8 +34,16 @@ jest.mock('@giphy/js-fetch-api', () => ({
|
||||
}))
|
||||
|
||||
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()
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user