Files
react-native/local-cli/core/__tests__/makeCommand.spec.js
James Burnett 3360999431 disable automock by default in as many places as possible @bypass-lint
Reviewed By: cpojer

Differential Revision: D5190858

fbshipit-source-id: d3125cf81427dbbe3362ef1f958413394a6dc51d
2017-06-08 07:45:54 -07:00

37 lines
878 B
JavaScript

jest.disableAutomock();
var spawnError = false;
jest.setMock('child_process', {
spawn: () => ({
on: (ev, cb) => cb(spawnError),
}),
});
jest.dontMock('../makeCommand');
const makeCommand = require('../makeCommand');
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();
});
});