hmil / ng-vacuum

Hassle-free unit tests for Angular
https://code.hmil.fr/ng-vacuum/
3 stars 1 forks source link

Mocking a local provider #32

Open hmil opened 3 years ago

hmil commented 3 years ago

How to mock a local provider declared in a component?

@Component({
   providers: [MyService]
})
class MyComponent {}
hmil commented 3 years ago

ng-vacuum does not automatically mock local providers. If you wish to mock them, you must manually do so using angular's TestBed:

import { getMock } from 'ng-vacuum';
import { instance } from 'omnimock';

beforeEach(() => {
    TestBed.overrideProvider(MyService, { useValue: instance(getMock(MyService)) });
});