Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 499d757

Browse filesBrowse files
committed
Improves unit tests
1 parent e53a7e8 commit 499d757
Copy full SHA for 499d757

File tree

Expand file treeCollapse file tree

10 files changed

+118
-51
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

10 files changed

+118
-51
lines changed
Open diff view settings
Collapse file

‎Week2/test/maartjes-work.test.js‎

Copy file name to clipboard
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
const { maartjesTasks, maartjesHourlyRate, computeEarnings } = require(`../homework/maartjes-work`);
22

3-
test('maartjes_work.js', () => {
4-
const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate);
5-
const result = earnings.toFixed(2);
6-
expect(result).toBe('373.33');
3+
describe('maartjes_work', () => {
4+
test('earnings rounded to euro cents', () => {
5+
const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate);
6+
const result = earnings.toFixed(2);
7+
expect(result).toBe('373.33');
8+
});
79
});
Collapse file

‎Week2/test/map-filter.test.js‎

Copy file name to clipboard
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const { myNumbers, doubleOddNumbers } = require(`../homework/map-filter`);
22

3-
test('map_filter.js', () => {
4-
const result = doubleOddNumbers(myNumbers);
5-
expect(result).toEqual([2, 6]);
3+
describe('map_filter', () => {
4+
test('result -> [2, 6]', () => {
5+
const result = doubleOddNumbers(myNumbers);
6+
expect(result).toEqual([2, 6]);
7+
});
68
});
Collapse file

‎Week3/test/step2-1.test.js‎

Copy file name to clipboardExpand all lines: Week3/test/step2-1.test.js
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ const foo = require('../homework/step2-1');
22

33
const mockFn = jest.fn(() => undefined);
44

5-
test('1-step3.js', () => {
6-
foo(mockFn);
7-
expect(mockFn.mock.calls.length).toBe(1);
5+
describe('step2-1', () => {
6+
test('foo calls func', () => {
7+
foo(mockFn);
8+
expect(mockFn.mock.calls.length).toBe(1);
9+
});
810
});
Collapse file

‎Week3/test/step2-2.test.js‎

Copy file name to clipboardExpand all lines: Week3/test/step2-2.test.js
+14-8Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,20 @@ const threeFive = require('../homework/step2-2');
33
const mockSayThree = jest.fn(() => undefined);
44
const mockSayFive = jest.fn(() => undefined);
55

6-
test('2-step3.js', () => {
7-
threeFive(10, 15, mockSayThree, mockSayFive);
6+
describe('step2-2', () => {
7+
test('12 and 15 divisible by 3', () => {
8+
threeFive(10, 15, mockSayThree, () => undefined);
89

9-
expect(mockSayThree.mock.calls.length).toBe(2);
10-
expect(mockSayThree.mock.calls[0][0]).toBe(12);
11-
expect(mockSayThree.mock.calls[1][0]).toBe(15);
10+
expect(mockSayThree.mock.calls.length).toBe(2);
11+
expect(mockSayThree.mock.calls[0][0]).toBe(12);
12+
expect(mockSayThree.mock.calls[1][0]).toBe(15);
13+
});
1214

13-
expect(mockSayFive.mock.calls.length).toBe(2);
14-
expect(mockSayFive.mock.calls[0][0]).toBe(10);
15-
expect(mockSayFive.mock.calls[1][0]).toBe(15);
15+
test('10 and 15 divisible by 5', () => {
16+
threeFive(10, 15, () => undefined, mockSayFive);
17+
18+
expect(mockSayFive.mock.calls.length).toBe(2);
19+
expect(mockSayFive.mock.calls[0][0]).toBe(10);
20+
expect(mockSayFive.mock.calls[1][0]).toBe(15);
21+
});
1622
});
Collapse file

‎Week3/test/step2-3.test.js‎

Copy file name to clipboardExpand all lines: Week3/test/step2-3.test.js
+44-13Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,68 @@ const {
44
repeatStringNumTimesWithDoWhile
55
} = require('../homework/step2-3');
66

7-
describe('1-step3.js', () => {
8-
test('for-loop', () => {
9-
let result = repeatStringNumTimesWithFor('abc', 3);
7+
describe('step2-3 with for-loop', () => {
8+
test('num = 3', () => {
9+
const result = repeatStringNumTimesWithFor('abc', 3);
1010
expect(result).toBe('abcabcabc');
11+
});
1112

12-
result = repeatStringNumTimesWithFor('abc', 1);
13+
test('num = 1', () => {
14+
const result = repeatStringNumTimesWithFor('abc', 1);
1315
expect(result).toBe('abc');
16+
});
1417

15-
result = repeatStringNumTimesWithFor('abc', -2);
18+
test('num = -2', () => {
19+
const result = repeatStringNumTimesWithFor('abc', -2);
1620
expect(result).toBe('');
1721
});
1822

19-
test('while-loop', () => {
20-
let result = repeatStringNumTimesWithWhile('abc', 3);
23+
test('num = 0', () => {
24+
const result = repeatStringNumTimesWithFor('abc', 0);
25+
expect(result).toBe('');
26+
});
27+
});
28+
29+
describe('step2-3 with while-loop', () => {
30+
test('num = 3', () => {
31+
const result = repeatStringNumTimesWithWhile('abc', 3);
2132
expect(result).toBe('abcabcabc');
33+
});
2234

23-
result = repeatStringNumTimesWithFor('abc', 1);
35+
test('num = 1', () => {
36+
const result = repeatStringNumTimesWithWhile('abc', 1);
2437
expect(result).toBe('abc');
38+
});
2539

26-
result = repeatStringNumTimesWithFor('abc', -2);
40+
test('num = 0', () => {
41+
const result = repeatStringNumTimesWithWhile('abc', 0);
2742
expect(result).toBe('');
2843
});
2944

30-
test('do-while-loop', () => {
31-
let result = repeatStringNumTimesWithDoWhile('abc', 3);
45+
test('num = -2', () => {
46+
const result = repeatStringNumTimesWithWhile('abc', -2);
47+
expect(result).toBe('');
48+
});
49+
});
50+
51+
describe('step2-3 with do-while-loop', () => {
52+
test('num = 3', () => {
53+
const result = repeatStringNumTimesWithDoWhile('abc', 3);
3254
expect(result).toBe('abcabcabc');
55+
});
3356

34-
result = repeatStringNumTimesWithFor('abc', 1);
57+
test('num = 1', () => {
58+
const result = repeatStringNumTimesWithDoWhile('abc', 1);
3559
expect(result).toBe('abc');
60+
});
61+
62+
test('num = 0', () => {
63+
const result = repeatStringNumTimesWithDoWhile('abc', 0);
64+
expect(result).toBe('');
65+
});
3666

37-
result = repeatStringNumTimesWithFor('abc', -2);
67+
test('num = -2', () => {
68+
const result = repeatStringNumTimesWithDoWhile('abc', -2);
3869
expect(result).toBe('');
3970
});
4071
});
Collapse file

‎Week3/test/step2-4.test.js‎

Copy file name to clipboard
+16-5Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
const hound = require('../homework/step2-4');
22

3-
test('4-step3', () => {
4-
expect(typeof hound).toBe('object');
5-
expect(typeof hound.name).toBe('string');
6-
expect(typeof hound.color).toBe('string');
7-
expect(typeof hound.numLegs).toBe('number');
3+
describe('step2-4', () => {
4+
test('hound to be an object', () => {
5+
expect(typeof hound).toBe('object');
6+
});
7+
8+
test('hound.name to be a string', () => {
9+
expect(typeof hound.name).toBe('string');
10+
});
11+
12+
test('hound.color to be a string', () => {
13+
expect(typeof hound.color).toBe('string');
14+
});
15+
16+
test('hound.numLegs to be a number', () => {
17+
expect(typeof hound.numLegs).toBe('number');
18+
});
819
});
Collapse file

‎Week3/test/step2-5.test.js‎

Copy file name to clipboard
+5-3Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
const multiplyAll = require('../homework/step2-5');
22

3-
test('5-step3.js', () => {
4-
const result = multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);
5-
expect(result).toBe(5040);
3+
describe('step2-5', () => {
4+
test('result to be product of array elements', () => {
5+
const result = multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);
6+
expect(result).toBe(5040);
7+
});
68
});
Collapse file

‎Week3/test/step2-6.test.js‎

Copy file name to clipboardExpand all lines: Week3/test/step2-6.test.js
+4-3Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-return-assign, dot-notation */
12
const { printArray2d, printArray3d } = require('../homework/step2-6');
23

34
const arr2d = [[1, 2], [3, 4], [5, 6]];
@@ -6,18 +7,18 @@ const expected2d = [1, 2, 3, 4, 5, 6].join('');
67
const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
78
const expected3d = [1, 2, 3, 4, 5, 6, 7, 8].join('');
89

9-
describe('6-step3.js', () => {
10+
describe('step2-6', () => {
1011
let outputData;
1112
const storeLog = (...inputs) => (outputData += inputs.join(' '));
1213

13-
test('printArray2d', () => {
14+
test('printArray2d -> 1, 2, 3, 4, 5, 6', () => {
1415
outputData = '';
1516
console['log'] = jest.fn(storeLog);
1617
printArray2d(arr2d);
1718
expect(outputData).toBe(expected2d);
1819
});
1920

20-
test('printArray2d', () => {
21+
test('printArray3d -> 1, 2, 3, 4, 5, 6, 7, 8', () => {
2122
outputData = '';
2223
console['log'] = jest.fn(storeLog);
2324
printArray3d(arr3d);
Collapse file

‎Week3/test/step3-bonus.test.js‎

Copy file name to clipboard
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
const makeUnique = require(`../homework/step3-bonus`);
22

3-
test('step4-bonus', () => {
4-
const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'];
5-
const expected = ['a', 'b', 'c', 'd', 'e', 'f'];
6-
const result = makeUnique(values);
7-
expect(result).toEqual(expected);
3+
describe('step3-bonus', () => {
4+
test('array should not contain duplicates', () => {
5+
const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'];
6+
const expected = ['a', 'b', 'c', 'd', 'e', 'f'];
7+
const result = makeUnique(values);
8+
expect(result).toEqual(expected);
9+
});
810
});
Collapse file

‎Week3/test/step3.test.js‎

Copy file name to clipboard
+12-4Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
const createBase = require(`../homework/step3`);
22

3-
test('step4.js', () => {
4-
const addSix = createBase(6);
5-
const result = addSix(10);
6-
expect(result).toBe(16);
3+
describe('step3', () => {
4+
test('base = 6', () => {
5+
const addSix = createBase(6);
6+
const result = addSix(10);
7+
expect(result).toBe(16);
8+
});
9+
10+
test('base = 10', () => {
11+
const addTen = createBase(10);
12+
const result = addTen(10);
13+
expect(result).toBe(20);
14+
});
715
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.