mirror of
https://github.com/kremalicious/portfolio.git
synced 2024-12-23 01:29:41 +01:00
getCountry test
This commit is contained in:
parent
d1d6c4b1f0
commit
7f0e1ca39d
@ -1,7 +1,5 @@
|
|||||||
import { getCountry } from './getCountry'
|
import { getCountry } from './getCountry'
|
||||||
|
|
||||||
const responseMock = 'loc=DE'
|
|
||||||
|
|
||||||
const mockFetch = data =>
|
const mockFetch = data =>
|
||||||
jest.fn().mockImplementationOnce(() =>
|
jest.fn().mockImplementationOnce(() =>
|
||||||
Promise.resolve({
|
Promise.resolve({
|
||||||
@ -13,15 +11,21 @@ const mockFetch = data =>
|
|||||||
)
|
)
|
||||||
|
|
||||||
describe('getCountry', () => {
|
describe('getCountry', () => {
|
||||||
beforeEach(() => {
|
|
||||||
global.fetch = mockFetch(responseMock)
|
|
||||||
})
|
|
||||||
|
|
||||||
it('fetches and returns correct value', async () => {
|
it('fetches and returns correct value', async () => {
|
||||||
|
global.fetch = mockFetch('loc=DE')
|
||||||
const country = await getCountry()
|
const country = await getCountry()
|
||||||
|
|
||||||
expect(global.fetch).toHaveBeenCalledTimes(1)
|
expect(global.fetch).toHaveBeenCalledTimes(1)
|
||||||
expect(global.fetch).toHaveBeenCalledWith('/cdn-cgi/trace?no-cache=1')
|
expect(global.fetch).toHaveBeenCalledWith('/cdn-cgi/trace?no-cache=1')
|
||||||
expect(country).toBe('DE')
|
expect(country).toBe('DE')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('returns nothing when XX country', async () => {
|
||||||
|
global.fetch = mockFetch('loc=XX')
|
||||||
|
const country = await getCountry()
|
||||||
|
|
||||||
|
expect(global.fetch).toHaveBeenCalledTimes(1)
|
||||||
|
expect(global.fetch).toHaveBeenCalledWith('/cdn-cgi/trace?no-cache=1')
|
||||||
|
expect(country).toBe(undefined)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user