emock automatically generates mocks from your classes. The entire public API will be mocked. It is especially designed to use in conjunction with ES6 classes (but not exclusive). Internally it uses expect spies. It has full TypeScript support and was developed for it!
npm i emock --save-dev
It is as simple as:
;;;: stringreturn s;;
See tests for more examples. :)
Like I said before
m.spyOn(x => x.echo('Foo')); records a call signature, but you don't have to use explicit values
like in the example above. You can use some matchers from the
It package. For example:
m;mmock;<any>; // passesmmock;<any>; // passesmmock;<any>; // fails with 5 is not a string
emock itself has no dependencies, but some peerDependencies.
You will need some polyfills for your environment if there is no support for used features:
- Reflect API with metadata support
Symbolpolyfill (comes with babel-polyfill for example)