0.2.1 • Published 7 years ago
jest-stub-methods v0.2.1
jest-stub-methods
Replace all methods on an object with spyable jest mocks.
Install
npm install jest-stub-methodsUsage
import stubMethods from 'jest-stub-methods';
describe('My Suite', () => {
  let stubbedConsole;
  beforeEach(() => {
    stubbedConsole = stubMethods(console);
  });
  afterEach(() => {
    stubbedConsole.restore();
  });
  it('logs a message', () => {
    console.log('Hello, World!');
    expect(stubbedConsole.stub.log).toHaveBeenCalledWith('Hello, World!');
    expect(console.log).toHaveBeenCalledWith('Hello, World!');
  });
  it('logs a warning', () => {
    console.warn('Attention!');
    expect(stubbedConsole.stub.warn).toHaveBeenCalledWith('Attention!');
    expect(console.warn).toHaveBeenCalledWith('Attention!');
  });
});License
MIT © 2019 SinnerSchrader Deutschland GmbH