2016-05-20 11:52:08 +00:00
|
|
|
var spawnError = false;
|
|
|
|
|
|
|
|
jest.setMock('child_process', {
|
|
|
|
spawn: () => ({
|
|
|
|
on: (ev, cb) => cb(spawnError),
|
|
|
|
}),
|
|
|
|
});
|
2016-08-22 15:56:14 +00:00
|
|
|
jest.dontMock('../makeCommand');
|
2016-05-20 11:52:08 +00:00
|
|
|
|
2016-08-22 15:56:14 +00:00
|
|
|
const makeCommand = require('../makeCommand');
|
2016-05-20 11:52:08 +00:00
|
|
|
|
|
|
|
describe('makeCommand', () => {
|
|
|
|
const command = makeCommand('echo');
|
|
|
|
|
|
|
|
it('should generate a function around shell command', () => {
|
|
|
|
expect(typeof command).toBe('function');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if there\'s no callback provided', () => {
|
|
|
|
expect(command).toThrow();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should invoke a callback after command execution', () => {
|
|
|
|
const spy = jest.genMockFunction();
|
|
|
|
command(spy);
|
|
|
|
|
|
|
|
expect(spy.mock.calls.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should throw an error if spawn ended up with error', () => {
|
|
|
|
spawnError = true;
|
|
|
|
const cb = jest.genMockFunction();
|
|
|
|
expect(() => command(cb)).toThrow();
|
|
|
|
});
|
|
|
|
});
|