Jest fixes 43

This commit is contained in:
karilint
2026-03-19 15:04:44 +02:00
parent c67fff41e0
commit 144def4c64
+11 -11
View File
@@ -29,25 +29,25 @@ const buildGeonamesResponse = (names: string[]): GeonamesJSON => ({
describe('Getting data from Geonames-API', () => {
beforeEach(() => {
jest.spyOn(global, 'fetch').mockImplementation(async input => {
const url = typeof input === 'string' ? input : input.toString()
jest.spyOn(global, 'fetch').mockImplementation(input => {
const url = typeof input === 'string' ? input : input.url
if (url.includes('Kumpula')) {
return {
json: async () =>
return Promise.resolve({
json: () =>
buildGeonamesResponse(['Kumpula', 'Kumpulantie', 'Kumpulanlaakso', 'Kumpulanmaki', 'Kumpula park']),
} as Response
} as Response)
}
if (url.includes('Tursola')) {
return {
json: async () => buildGeonamesResponse(['Tursola', 'Tursola village']),
} as Response
return Promise.resolve({
json: () => buildGeonamesResponse(['Tursola', 'Tursola village']),
} as Response)
}
return {
json: async () => buildGeonamesResponse([]),
} as Response
return Promise.resolve({
json: () => buildGeonamesResponse([]),
} as Response)
})
})