-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.js
69 lines (59 loc) · 2.07 KB
/
index.spec.js
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
import { buildRocket, fetchCrew, getFuel, bookLaunchPad } from './index.mjs';
import { run } from './example.mjs';
let consoleLogSpy;
beforeEach(() => {
consoleLogSpy = jest.spyOn(global.console, 'log').mockImplementation(jest.fn());
});
afterEach(() => {
consoleLogSpy.mockRestore();
});
jest.setTimeout(30 * 1000);
describe('buildRocket', () => {
it('should return a rocket in 5 seconds', async () => {
const start = Date.now();
const rocket = await buildRocket();
expect(typeof rocket.addCrew).toBe('function');
expect(typeof rocket.addFuel).toBe('function');
expect(typeof rocket.fireEngine).toBe('function');
expect(typeof rocket.stopEngine).toBe('function');
expect(typeof rocket.engineIsFiring).toBe('function');
expect(typeof rocket.runStageSeparation).toBe('function');
expect(Math.floor((Date.now() - start) / 1000)).toBe(5);
expect(consoleLogSpy.mock.calls).toEqual([
['Building rocket...'],
['Rocket built!'],
]);
});
});
describe('fetchCrew', () => {
it('should return a crew array in 3 seconds', async () => {
const start = Date.now();
const crew = await fetchCrew();
expect(Array.isArray(crew)).toBe(true);
expect(crew.length).toBe(2);
expect(Math.floor((Date.now() - start) / 1000)).toBe(3);
});
});
describe('getFuel', () => {
it('should return fuel in 1 second', async () => {
const start = Date.now();
const fuel = await getFuel();
expect(Math.floor((Date.now() - start) / 1000)).toBe(1);
});
});
describe('bookLaunchPad', () => {
it('should return a launchPad object in 5 seconds', async () => {
const start = Date.now();
const launchPad = await bookLaunchPad();
expect(typeof launchPad.addRocket).toBe('function');
expect(Math.floor((Date.now() - start) / 1000)).toBe(5);
});
});
describe('integration', () => {
it('should run the whole mission in 11 seconds!', async () => {
const start = Date.now();
await run();
expect(Math.floor((Date.now() - start) / 1000)).toBe(11);
expect(consoleLogSpy.mock.calls).toMatchSnapshot();
}, 30 * 1000);
});