mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-04 22:56:32 +08:00
Summary: Renamed test files to match `-test.js`, so people can add test helpers without blacklisting. Codemod code: P60365841 Script executed: ``` cd xplat/js ./scripts/node/node rename-script.js > result.txt ``` Reviewed By: mjesun Differential Revision: D13185673 fbshipit-source-id: 87451635aa538c2c1d1886e75574d0e5c889596e
48 lines
1.0 KiB
JavaScript
48 lines
1.0 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* 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();
|
|
});
|
|
});
|