mirror of
https://github.com/ershisan99/go-npm.git
synced 2025-12-17 05:09:30 +00:00
ADD unit tests, split and refactor source code
This commit is contained in:
40
__test__/cli.spec.js
Normal file
40
__test__/cli.spec.js
Normal file
@@ -0,0 +1,40 @@
|
||||
const cli = require('../src/cli');
|
||||
const install = require('../src/actions/install');
|
||||
|
||||
jest.mock('../src/actions/install');
|
||||
|
||||
describe('cli()', () => {
|
||||
let exit;
|
||||
|
||||
beforeEach(() => {
|
||||
exit = jest.fn();
|
||||
});
|
||||
|
||||
it('should exit with error if not enough args are supplied', () => {
|
||||
cli({ argv: [], exit });
|
||||
|
||||
expect(exit).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
it('should exit with error if command does not exist', () => {
|
||||
cli({ argv: [ '/usr/local/bin/node', 'index.js', 'command' ], exit });
|
||||
|
||||
expect(exit).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
it('should exit with error if command returns error', () => {
|
||||
install.mockImplementationOnce((cb) => cb(new Error()));
|
||||
|
||||
cli({ argv: [ '/usr/local/bin/node', 'index.js', 'install' ], exit });
|
||||
|
||||
expect(exit).toHaveBeenCalledWith(1);
|
||||
});
|
||||
|
||||
it('should exit with success if command runs fine', () => {
|
||||
install.mockImplementationOnce((cb) => cb(null));
|
||||
|
||||
cli({ argv: [ '/usr/local/bin/node', 'index.js', 'install' ], exit });
|
||||
|
||||
expect(exit).toHaveBeenCalledWith(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user