0.5.0 • Published 8 years ago

execa-jest-mock v0.5.0

Weekly downloads
225
License
MIT
Repository
github
Last release
8 years ago

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.