-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise-2.test.js
More file actions
50 lines (45 loc) · 1.31 KB
/
exercise-2.test.js
File metadata and controls
50 lines (45 loc) · 1.31 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
const exerciseTwo = require('./exercise-2')
const countryData = require('./country-data');
describe('Exercise 2', () => {
test('Uses filter method', () => {
const inputArray = [];
const filterSpy = jest.spyOn(inputArray, 'filter');
exerciseTwo(inputArray);
expect(filterSpy).toHaveBeenCalled();
})
test('Does not modify input array', () => {
const inputArray = [...countryData];
exerciseTwo(inputArray);
expect(inputArray).toEqual(countryData);
})
test('Returns United Kingdom when Europe is passed', () => {
const result = exerciseTwo(countryData, 'Europe');
expect(result).toEqual([{
name: 'United Kingdom',
continent: 'Europe',
population: 67530172,
landArea: 241930,
}])
})
test('Returns Nigeria & Kenya when Africa is passed', () => {
const result = exerciseTwo(countryData, 'Africa');
expect(result).toEqual([
{
name: 'Nigeria',
continent: 'Africa',
population: 200963599,
landArea: 910768,
},
{
name: 'Kenya',
continent: 'Africa',
population: 52573973,
landArea: 569140,
},
])
})
test('Returns empty array if South America is passed', () => {
const result = exerciseTwo(countryData, 'South America');
expect(result).toEqual([])
})
})