This repository was archived by the owner on May 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment.test.js
More file actions
81 lines (69 loc) · 2.01 KB
/
Copy pathassignment.test.js
File metadata and controls
81 lines (69 loc) · 2.01 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import fizzbuzzify from 'fizzbuzzify';
import {
first,
second,
third,
fourth,
fifth,
sixth,
} from './assignment';
const spy = jest.spyOn(global.console, 'log');
describe('javascript-introduction assignments', () => {
test('first', () => {
spy.mockClear();
expect(first).toBeInstanceOf(Function);
first();
expect(spy).toHaveBeenCalledTimes(6);
expect(typeof spy.mock.calls[0][0]).toBe('number');
expect(typeof spy.mock.calls[1][0]).toBe('string');
expect(typeof spy.mock.calls[2][0]).toBe('boolean');
expect(spy.mock.calls[3][0]).toBeNull();
expect(spy.mock.calls[4].length).toBe(2);
expect(spy.mock.calls[5].length).toBe(3);
});
test('second', () => {
expect(second).toBeInstanceOf(Function);
[1, '2', true, null, undefined].forEach((value) => {
expect(second(value)).toBe(typeof value);
});
});
test('third', () => {
expect(third).toBeInstanceOf(Function);
for (let i = 0; i < 20; i += 1) {
const a = Math.random();
const b = Math.random();
expect(third.call(null, a, b)).toBe(Math.max(a, b));
}
});
test('fourth', () => {
expect(fourth).toBeInstanceOf(Function);
for (let i = 0; i < 20; i += 1) {
const args = [
Math.random(),
Math.random(),
Math.random(),
Math.random(),
Math.random(),
Math.random(),
Math.random(),
Math.random(),
];
expect(fourth(...args)).toBe(Math.max(...args));
}
});
test('fifth', () => {
spy.mockClear();
expect(fifth).toBeInstanceOf(Function);
fifth();
const length = 100;
expect(spy).toHaveBeenCalledTimes(length);
expect(spy.mock.calls.every((call, ix) => String(call[0]) === fizzbuzzify(ix + 1))).toBe(true);
});
test('sixth', () => {
spy.mockClear();
expect(sixth).toBeInstanceOf(Function);
sixth();
expect(spy).toHaveBeenCalledTimes(7);
expect(spy.mock.calls.every((call, ix) => call[0].replace(/[^#]/g, '').length === ix + 1)).toBe(true);
});
});