execa-jest-mock
v0.5.0
Published
Mock execa for Jest
Downloads
480
Maintainers
Readme
execa-mock-jest
Mock execa for Jest
Install
$ npm install --save execa-mock-jest
Usage
Use as a manual mock:
// __mocks__/execa.js
module.exports = require('execa-mock-jest');
// something.test.js
const execa = require('execa');
it('mocks execa', () => {
execa.__setMockResults([
'Something has been removed'
// Supports:
// 'stdout'
// ['stdout', code]
// ['stdout', 'stderr', code]
// { stdout, stderr, code }
]);
return execa('rm', ['*']).then(result =>
expect(result).toEqual({
stdout: 'Something has been removed',
stderr: '',
code: 0,
failed: false,
killed: false,
signal: null,
cmd: 'rm *'
});
expect(execa).toHaveBeenCalledTimes(1);
);
});
Nota Bene
Results order is not reliable when used with concurrent tests.