2.0.0 • Published 3 years ago

jasmine-ts-auto-mock v2.0.0

Weekly downloads
182
License
ISC
Repository
github
Last release
3 years ago

Jasmine Ts Auto Mock

Actions Status

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

Requirements

typescript@^3.2.2

Installation

Examples

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-ignore
window.__importDefault = function(mod) {
    return mod && mod.__esModule ? mod : { default: mod };
};

Usage

1) create an interface

interface Interface {
    methodToMock: () => string
}

2) create a mock

const mock: Interface = createMock<Interface>();

3) get the method mock

You can get the method spy in 2 different ways

Through method

import { On, method } from "ts-auto-mock/extension";
const mockMethod: jasmine.Spy = On(mock).get(method(mock => mock.methodToMock));

Through string

import { On, method } from "ts-auto-mock/extension";
const mockMethod: jasmine.Spy = On(mock).get(method('methodToMock'));

4) trigger the method

someMethodThatWillTriggerInterfacemethodToMock();
expect(mockMethod).toHaveBeenCalled();

Authors

License

This project is licensed under the MIT License

2.0.0

3 years ago

1.0.11

3 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago