@redocly/cli
Version:
[@Redocly](https://redocly.com) CLI is your all-in-one OpenAPI utility. It builds, manages, improves, and quality-checks your OpenAPI descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make API g
52 lines (41 loc) • 1.23 kB
text/typescript
import { Spinner } from '../utils/spinner';
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);
});
});