-
Notifications
You must be signed in to change notification settings - Fork 165
/
Copy pathspinner.test.ts
51 lines (41 loc) · 1.21 KB
/
spinner.test.ts
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
import { Spinner } from '../utils/spinner.js';
import * as process from 'process';
jest.useFakeTimers();
describe('Spinner', () => {
const IS_TTY = process.stdout.isTTY;
let writeMock: jest.SpyInstance;
let spinner: Spinner;
beforeEach(() => {
process.stdout.isTTY = true;
writeMock = jest.spyOn(process.stdout, 'write').mockImplementation(jest.fn());
spinner = new Spinner();
});
afterEach(() => {
writeMock.mockRestore();
jest.clearAllTimers();
});
afterAll(() => {
process.stdout.isTTY = IS_TTY;
});
it('starts the spinner', () => {
spinner.start('Loading');
jest.advanceTimersByTime(100);
expect(writeMock).toHaveBeenCalledWith('\r⠋ Loading');
});
it('stops the spinner', () => {
spinner.start('Loading');
spinner.stop();
expect(writeMock).toHaveBeenCalledWith('\r');
});
it('should write 3 frames', () => {
spinner.start('Loading');
jest.advanceTimersByTime(300);
expect(writeMock).toHaveBeenCalledTimes(3);
});
it('should call write 1 times if CI set to true', () => {
process.stdout.isTTY = false;
spinner.start('Loading');
jest.advanceTimersByTime(300);
expect(writeMock).toHaveBeenCalledTimes(1);
});
});