Jasmine test utility with automatic mock creation for interfaces and classes
npm install jasmine-ts-auto-mock
This is a library that extend ts-auto-mock to be used with jasmine
The intention of the library is to automatically assign spies to mocks giving you type safety
typescript@^3.2.2
- A Transformer needs to be provided at compile time. There are different ways to do it.
Please read the following guide to find your configuration
- provide jasmine-ts-auto-mock before your test
Please read the following guide to find your configuration
If you are using angular with typescript 3.7 you need to follow the solution in this issue:
https://github.com/angular/angular-cli/issues/16071
Add this in the polyfill until angular support typescript 3.7
``ts`
// @ts-ignore
window.__importDefault = function(mod) {
return mod && mod.__esModule ? mod : { default: mod };
};
ts
interface Interface {
methodToMock: () => string
}
`
2) create a mock
`ts
const mock: Interface = createMock();
`
3) get the method mock You can get the method spy in 2 different ways
Through method
`ts
import { On, method } from "ts-auto-mock/extension";
const mockMethod: jasmine.Spy = On(mock).get(method(mock => mock.methodToMock));
`Through string
`ts
import { On, method } from "ts-auto-mock/extension";
const mockMethod: jasmine.Spy = On(mock).get(method('methodToMock'));
`4) trigger the method
`ts
someMethodThatWillTriggerInterfacemethodToMock();
expect(mockMethod).toHaveBeenCalled();
``* Vittorio Guerriero
* Giulio Caprino
This project is licensed under the MIT License