-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise-4.test.js
More file actions
60 lines (56 loc) · 1.51 KB
/
exercise-4.test.js
File metadata and controls
60 lines (56 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const exerciseFour = require('./exercise-4')
const countryData = require('./country-data');
describe('Exercise 4', () => {
test('Uses map method', () => {
const inputArray = [];
const mapSpy = jest.spyOn(inputArray, 'map');
exerciseFour(inputArray);
expect(mapSpy).toHaveBeenCalled();
})
test('Does not modify input array', () => {
const inputArray = [...countryData];
exerciseFour(inputArray);
expect(inputArray).toEqual(countryData);
})
const expectedResult = [
{
name: 'United Kingdom',
continent: 'Europe',
population: 67530172,
landArea: 241930,
populationDensity: 279.1310379035258,
},
{
name: 'Federated States of Micronesia',
continent: 'Oceania',
population: 113815,
landArea: 702,
populationDensity: 162.12962962962962,
},
{
name: 'Bangladesh',
continent: 'Asia',
population: 163046161,
landArea: 130168,
populationDensity: 1252.5825164402925,
},
{
name: 'Nigeria',
continent: 'Africa',
population: 200963599,
landArea: 910768,
populationDensity: 220.65289843297086,
},
{
name: 'Kenya',
continent: 'Africa',
population: 52573973,
landArea: 569140,
populationDensity: 92.37441227114594,
},
];
test('Adds population density to every country', () => {
const result = exerciseFour(countryData);
expect(result).toEqual(expectedResult)
})
})