testing/src/progress-indicator.mock.ts
Mock class of the StarkProgressIndicatorService interface.
SpyObj
Properties |
|
Public deregister |
Type : Spy<>
|
Default value : createSpy("deregister")
|
Defined in testing/src/progress-indicator.mock.ts:18
|
See StarkProgressIndicatorService deregister() method |
Public hide |
Type : Spy<>
|
Default value : createSpy("hide")
|
Defined in testing/src/progress-indicator.mock.ts:28
|
See StarkProgressIndicatorService hide() method |
Public isVisible |
Type : Spy<>
|
Default value : createSpy("isVisible")
|
Defined in testing/src/progress-indicator.mock.ts:33
|
See StarkProgressIndicatorService isVisible() method |
Public register |
Type : Spy<>
|
Default value : createSpy("register")
|
Defined in testing/src/progress-indicator.mock.ts:13
|
See StarkProgressIndicatorService register() method |
Public show |
Type : Spy<>
|
Default value : createSpy("show")
|
Defined in testing/src/progress-indicator.mock.ts:23
|
See StarkProgressIndicatorService show() method |
The mock class MockStarkProgressIndicatorService
can be imported as follows:
import { MockStarkProgressIndicatorService } from "@nationalbankbelgium/stark-ui/testing";
Since the mock class implements the base interface of the service it mocks, you just need to provide the mock in your TestingModule
:
TestBed.configureTestingModule({
imports: [...],
declarations: [...],
providers: [
...
{ provide: STARK_PROGRESS_INDICATOR_SERVICE, useValue: new MockStarkProgressIndicatorService() },
...
]
});
Then you can just inject the Stark service via the TestBed using its corresponding InjectionToken
:
// this will inject the instantiated mock class
mockStarkProgressIndicatorService = TestBed.inject(STARK_PROGRESS_INDICATOR_SERVICE);
In fact, every method of the base interface is simply mocked with a Jasmine Spy which can then be used in the unit tests to:
For example:
Example :// returning custom value
mockStarkProgressIndicatorService.isVisible.and.returnValue(someCustomObservable);
// overriding a method with a custom function
mockStarkProgressIndicatorService.show.and.callFake((topic: string) => {
// some custom logic
});
// asserting that a method was indeed called
expect(mockStarkProgressIndicatorService.show).toHaveBeenCalledTimes(1);
import { StarkProgressIndicatorService } from "@nationalbankbelgium/stark-ui";
import Spy = jasmine.Spy;
import SpyObj = jasmine.SpyObj;
import createSpy = jasmine.createSpy;
/**
* Mock class of the {@link StarkProgressIndicatorService} interface.
*/
export class MockStarkProgressIndicatorService implements SpyObj<StarkProgressIndicatorService> {
/**
* See [StarkProgressIndicatorService register()]{@link StarkProgressIndicatorService#register} method
*/
public register: Spy<StarkProgressIndicatorService["register"]> = createSpy("register");
/**
* See [StarkProgressIndicatorService deregister()]{@link StarkProgressIndicatorService#deregister} method
*/
public deregister: Spy<StarkProgressIndicatorService["deregister"]> = createSpy("deregister");
/**
* See [StarkProgressIndicatorService show()]{@link StarkProgressIndicatorService#show} method
*/
public show: Spy<StarkProgressIndicatorService["show"]> = createSpy("show");
/**
* See [StarkProgressIndicatorService hide()]{@link StarkProgressIndicatorService#hide} method
*/
public hide: Spy<StarkProgressIndicatorService["hide"]> = createSpy("hide");
/**
* See [StarkProgressIndicatorService isVisible()]{@link StarkProgressIndicatorService#isVisible} method
*/
public isVisible: Spy<StarkProgressIndicatorService["isVisible"]> = createSpy("isVisible");
}