Skip to content

azz/jest-magic-mock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jest-magic-mock

EXPERIMENT: Do not actually use this, I think?

This is a JavaScript implementation of a Magic Mock, inspired by Python's unittest.mock.MagicMock. It is implemented using Proxy.

API

import magicMock from 'jest-magic-mock';

test('has all of the properties', () => {
  const mock = magicMock();

  expect(mock.foo.bar.baz[2]).toBeDefined();
});

test('can mock individual properties', () => {
  const mock = magicMock();

  mock.foo.mockReturnValue(3);
  mock.bar.baz.mockImplementation(x => x * x);

  expect(mock.foo()).toEqual(3);
  expect(mock.bar.baz(3)).toEqual(9);
  expect(mock()).toEqual(undefined);
});

See the tests for more examples.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published