react-native/local-cli/core/__tests__/makeCommand.spec.js
Sophie Alpert 1490ab12ef Update license headers for MIT license
Summary:
Includes React Native and its dependencies Fresco, Metro, and Yoga. Excludes samples/examples/docs.

find: ^(?:( *)|( *(?:[\*~#]|::))( )? *)?Copyright (?:\(c\) )?(\d{4})\b.+Facebook[\s\S]+?BSD[\s\S]+?(?:this source tree|the same directory)\.$
replace: $1$2$3Copyright (c) $4-present, Facebook, Inc.\n$2\n$1$2$3This source code is licensed under the MIT license found in the\n$1$2$3LICENSE file in the root directory of this source tree.

Reviewed By: TheSavior, yungsters

Differential Revision: D7007050

fbshipit-source-id: 37dd6bf0ffec0923bfc99c260bb330683f35553e
2018-02-16 18:31:53 -08:00

48 lines
1.0 KiB
JavaScript

/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @emails oncall+javascript_foundation
*/
'use strict';
let spawnError = false;
jest.setMock('child_process', {
spawn: () => ({
on: (event, cb) => cb(spawnError),
}),
});
const makeCommand = require('../makeCommand');
describe('makeCommand', () => {
const command = makeCommand('echo');
it('generates a function around shell command', () => {
expect(typeof command).toBe('function');
});
it('throws an error if there is no callback provided', () => {
expect(command).toThrow();
});
it('invokes a callback after command execution', () => {
const spy = jest.fn();
command(spy);
expect(spy.mock.calls).toHaveLength(1);
});
it('throws an error if spawn ended up with error', () => {
spawnError = true;
const cb = jest.fn();
expect(() => {
command(cb);
}).toThrow();
});
});