execa-jest-mock

0.5.0 • Public • Published

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.

Package Sidebar

Install

npm i execa-jest-mock

Weekly Downloads

3

Version

0.5.0

License

MIT

Last publish

Collaborators

  • simon.degraeve