UNPKG

johnny-cli

Version:

CLI for Johnny Deps

42 lines (33 loc) 1.25 kB
import fs from 'fs'; import startCmd from '../'; jest.mock('fs'); jest.mock('promptly'); const mockJohnnyRemove = jest.fn(), mockAPIStart = jest.fn(), name = 'newdll', packages = {package: 'version'}; jest.mock('API', () => () => ({ requestToken: () => new Promise(resolve => resolve('token')), start : mockAPIStart, })); jest.mock('JohnnyFile', () => () => ({ create: function() { return this; }, get : new Function, remove: mockJohnnyRemove, })); describe('"start" command', () => { beforeEach(() => fs.__setMockFiles({'./package.json': `{"dependencies": ${JSON.stringify(packages)}}`})); it('sends packages names and versions to API', async () => { fs.__setMockFiles({'./package.json': `{"dependencies": ${JSON.stringify(packages)}}`}); await startCmd('newdll'); // Pass unresolved Promise in order to prevent program flow to go further mockAPIStart.mockImplementation(new Promise(new Function)); expect(mockAPIStart).toHaveBeenCalledWith({name, packages: packages}); }); it('removes johnny config file if API request failed', async () => { mockAPIStart.mockImplementation(() => new Promise((resolve, reject) => reject())); await startCmd('newdll'); expect(mockJohnnyRemove).toHaveBeenCalled(); }); });