Skip to content

Commit d087bc1

Browse files
committed
make fetchGameData able to take an optional parameter
relates #3
1 parent b14c014 commit d087bc1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

utils/fetchGameData/fetchGameData.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'whatwg-fetch';
22

33
// eslint-disable-next-line
4-
export default () => fetch('https://restcountries.eu/rest/v2/region/europe')
4+
export default (region = 'europe') => fetch(`https://restcountries.eu/rest/v2/region/${region}`)
55
.then(res => {
66
if (res.status !== 200) {
77
throw new Error(`Fetch responded with status: ${res.status}`);

utils/fetchGameData/fetchGameData.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ describe('Test fetchGameData', () => {
1010
afterAll(() => fetchMock.restore());
1111

1212
test('Test fetchGameData is mocked', () => {
13-
return fetchGameData()
13+
return fetchGameData('europe')
1414
.then((countriesArray) => {
1515
expect(countriesArray.length).toBe(dummyGameData.length);
1616
});
1717
});
1818

1919
test('Test fetchGameData response format', async () => {
20-
const countriesArray = await fetchGameData();
20+
const countriesArray = await fetchGameData('europe');
2121
expect(countriesArray.length).toBe(dummyGameData.length);
2222
const mergedCountriesObj = countriesArray
2323
.reduce((accumulator, currentObj) => Object.assign(accumulator, currentObj), {});
@@ -29,7 +29,7 @@ describe('Test fetchGameData', () => {
2929

3030
describe('Test fetchGameData after mocking', () => {
3131
test('Test fetchGameData was mocked', () => {
32-
return fetchGameData()
32+
return fetchGameData('europe')
3333
.then((countriesArray) => {
3434
expect(countriesArray.length).not.toBe(dummyGameData.length)
3535
});

0 commit comments

Comments
 (0)