-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise-3.test.js
More file actions
34 lines (29 loc) · 967 Bytes
/
exercise-3.test.js
File metadata and controls
34 lines (29 loc) · 967 Bytes
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
const exerciseThree = require('./exercise-3')
describe('Exercise 3', () => {
test('Uses map method', () => {
const inputArray = [];
const mapSpy = jest.spyOn(inputArray, 'map');
exerciseThree(inputArray);
expect(mapSpy).toHaveBeenCalled();
})
test('Does not modify input array', () => {
const inputArray = [1, 2];
exerciseThree(inputArray);
expect(inputArray).toEqual([1, 2]);
})
test('Doubles all numbers in the array', () => {
const inputArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const result = exerciseThree(inputArray);
expect(result).toEqual([2, 4, 6, 8, 10, 12, 14, 16, 18, 20])
})
test('Handles 0 in input', () => {
const inputArray = [0];
const result = exerciseThree(inputArray);
expect(result).toEqual([0])
})
test('Handles negative numbers in input', () => {
const inputArray = [-1, -3];
const result = exerciseThree(inputArray);
expect(result).toEqual([-2, -6])
})
})