testing/src/routing.mock.ts
Mock class of the StarkRoutingService interface.
SpyObj
Properties |
|
Public addKnownNavigationRejectionCause |
Type : Spy<>
|
Default value : createSpy("addKnownNavigationRejectionCause")
|
Defined in testing/src/routing.mock.ts:94
|
Public addTransitionHook |
Type : Spy<>
|
Default value : createSpy("addTransitionHook")
|
Defined in testing/src/routing.mock.ts:100
|
See StarkRoutingService addTransitionHook() method |
Public getCurrentState |
Type : Spy<>
|
Default value : createSpy("getCurrentState")
|
Defined in testing/src/routing.mock.ts:38
|
See StarkRoutingService getCurrentState() method |
Public getCurrentStateConfig |
Type : Spy<>
|
Default value : createSpy("getCurrentStateConfig")
|
Defined in testing/src/routing.mock.ts:43
|
See StarkRoutingService getCurrentStateConfig() method |
Public getCurrentStateName |
Type : Spy<>
|
Default value : createSpy("getCurrentStateName")
|
Defined in testing/src/routing.mock.ts:33
|
See StarkRoutingService getCurrentStateName() method |
Public getCurrentStateParams |
Type : Spy<>
|
Default value : createSpy("getCurrentStateParams")
|
Defined in testing/src/routing.mock.ts:64
|
See StarkRoutingService getCurrentStateParams() method |
Public getStateConfigByUrlPath |
Type : Spy<>
|
Default value : createSpy("getStateConfigByUrlPath")
|
Defined in testing/src/routing.mock.ts:53
|
Public getStateDeclarationByStateName |
Type : Spy<>
|
Default value : createSpy("getStateDeclarationByStateName")
|
Defined in testing/src/routing.mock.ts:58
|
Public getStatesConfig |
Type : Spy<>
|
Default value : createSpy("getStatesConfig")
|
Defined in testing/src/routing.mock.ts:48
|
See StarkRoutingService getStatesConfig() method |
Public getStateTreeData |
Type : Spy<>
|
Default value : createSpy("getStateTreeData")
|
Defined in testing/src/routing.mock.ts:79
|
See StarkRoutingService getStateTreeData() method |
Public getStateTreeParams |
Type : Spy<>
|
Default value : createSpy("getStateTreeParams")
|
Defined in testing/src/routing.mock.ts:69
|
See StarkRoutingService getStateTreeParams() method |
Public getStateTreeResolves |
Type : Spy<>
|
Default value : createSpy("getStateTreeResolves")
|
Defined in testing/src/routing.mock.ts:74
|
See StarkRoutingService getStateTreeResolves() method |
Public getTranslationKeyFromState |
Type : Spy<>
|
Default value : createSpy("getTranslationKeyFromState")
|
Defined in testing/src/routing.mock.ts:105
|
Public isCurrentUiState |
Type : Spy<>
|
Default value : createSpy("isCurrentUiState")
|
Defined in testing/src/routing.mock.ts:84
|
See StarkRoutingService isCurrentUiState() method |
Public isCurrentUiStateIncludedIn |
Type : Spy<>
|
Default value : createSpy("includesState")
|
Defined in testing/src/routing.mock.ts:89
|
Public navigateTo |
Type : Spy<>
|
Default value : createSpy("navigateTo")
|
Defined in testing/src/routing.mock.ts:13
|
See StarkRoutingService navigateTo() method |
Public navigateToHome |
Type : Spy<>
|
Default value : createSpy("navigateToHome")
|
Defined in testing/src/routing.mock.ts:18
|
See StarkRoutingService navigateToHome() method |
Public navigateToPrevious |
Type : Spy<>
|
Default value : createSpy("navigateToPrevious")
|
Defined in testing/src/routing.mock.ts:23
|
See StarkRoutingService navigateToPrevious() method |
Public reload |
Type : Spy<>
|
Default value : createSpy("reload")
|
Defined in testing/src/routing.mock.ts:28
|
See StarkRoutingService reload() method |
The mock class MockStarkRoutingService
can be imported as follows:
import { MockStarkRoutingService } from "@nationalbankbelgium/stark-core/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_ROUTING_SERVICE, useValue: new MockStarkRoutingService() },
...
]
});
Then you can just inject the Stark service via the TestBed using its corresponding InjectionToken
:
// this will inject the instantiated mock class
mockRoutingService = TestBed.inject(STARK_ROUTING_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
mockRoutingService.isCurrentUiState.and.returnValue(false);
// overriding a method with a custom function
mockRoutingService.isCurrentUiState.and.callFake((someState) => {
// some custom logic to return a specific value
});
// asserting that a method was indeed called
expect(mockRoutingService.isCurrentUiState).toHaveBeenCalledTimes(1);
expect(mockRoutingService.isCurrentUiState).toHaveBeenCalledWith(someState, someParams);
import { StarkRoutingService } from "@nationalbankbelgium/stark-core";
import Spy = jasmine.Spy;
import SpyObj = jasmine.SpyObj;
import createSpy = jasmine.createSpy;
/**
* Mock class of the {@link StarkRoutingService} interface.
*/
export class MockStarkRoutingService implements SpyObj<StarkRoutingService> {
/**
* See [StarkRoutingService navigateTo()]{@link StarkRoutingService#navigateTo} method
*/
public navigateTo: Spy<StarkRoutingService["navigateTo"]> = createSpy("navigateTo");
/**
* See [StarkRoutingService navigateToHome()]{@link StarkRoutingService#navigateToHome} method
*/
public navigateToHome: Spy<StarkRoutingService["navigateToHome"]> = createSpy("navigateToHome");
/**
* See [StarkRoutingService navigateToPrevious()]{@link StarkRoutingService#navigateToPrevious} method
*/
public navigateToPrevious: Spy<StarkRoutingService["navigateToPrevious"]> = createSpy("navigateToPrevious");
/**
* See [StarkRoutingService reload()]{@link StarkRoutingService#reload} method
*/
public reload: Spy<StarkRoutingService["reload"]> = createSpy("reload");
/**
* See [StarkRoutingService getCurrentStateName()]{@link StarkRoutingService#getCurrentStateName} method
*/
public getCurrentStateName: Spy<StarkRoutingService["getCurrentStateName"]> = createSpy("getCurrentStateName");
/**
* See [StarkRoutingService getCurrentState()]{@link StarkRoutingService#getCurrentState} method
*/
public getCurrentState: Spy<StarkRoutingService["getCurrentState"]> = createSpy("getCurrentState");
/**
* See [StarkRoutingService getCurrentStateConfig()]{@link StarkRoutingService#getCurrentStateConfig} method
*/
public getCurrentStateConfig: Spy<StarkRoutingService["getCurrentStateConfig"]> = createSpy("getCurrentStateConfig");
/**
* See [StarkRoutingService getStatesConfig()]{@link StarkRoutingService#getStatesConfig} method
*/
public getStatesConfig: Spy<StarkRoutingService["getStatesConfig"]> = createSpy("getStatesConfig");
/**
* See [StarkRoutingService getStateConfigByUrlPath()]{@link StarkRoutingService#getStateConfigByUrlPath} method
*/
public getStateConfigByUrlPath: Spy<StarkRoutingService["getStateConfigByUrlPath"]> = createSpy("getStateConfigByUrlPath");
/**
* See [StarkRoutingService getStateDeclarationByStateName()]{@link StarkRoutingService#getStateDeclarationByStateName} method
*/
public getStateDeclarationByStateName: Spy<StarkRoutingService["getStateDeclarationByStateName"]> =
createSpy("getStateDeclarationByStateName");
/**
* See [StarkRoutingService getCurrentStateParams()]{@link StarkRoutingService#getCurrentStateParams} method
*/
public getCurrentStateParams: Spy<StarkRoutingService["getCurrentStateParams"]> = createSpy("getCurrentStateParams");
/**
* See [StarkRoutingService getStateTreeParams()]{@link StarkRoutingService#getStateTreeParams} method
*/
public getStateTreeParams: Spy<StarkRoutingService["getStateTreeParams"]> = createSpy("getStateTreeParams");
/**
* See [StarkRoutingService getStateTreeResolves()]{@link StarkRoutingService#getStateTreeResolves} method
*/
public getStateTreeResolves: Spy<StarkRoutingService["getStateTreeResolves"]> = createSpy("getStateTreeResolves");
/**
* See [StarkRoutingService getStateTreeData()]{@link StarkRoutingService#getStateTreeData} method
*/
public getStateTreeData: Spy<StarkRoutingService["getStateTreeData"]> = createSpy("getStateTreeData");
/**
* See [StarkRoutingService isCurrentUiState()]{@link StarkRoutingService#isCurrentUiState} method
*/
public isCurrentUiState: Spy<StarkRoutingService["isCurrentUiState"]> = createSpy("isCurrentUiState");
/**
* See [StarkRoutingService isCurrentUiStateIncludedIn()]{@link StarkRoutingService#isCurrentUiStateIncludedIn} method
*/
public isCurrentUiStateIncludedIn: Spy<StarkRoutingService["isCurrentUiStateIncludedIn"]> = createSpy("includesState");
/**
* See [StarkRoutingService addKnownNavigationRejectionCause()]{@link StarkRoutingService#addKnownNavigationRejectionCause} method
*/
public addKnownNavigationRejectionCause: Spy<StarkRoutingService["addKnownNavigationRejectionCause"]> =
createSpy("addKnownNavigationRejectionCause");
/**
* See [StarkRoutingService addTransitionHook()]{@link StarkRoutingService#addTransitionHook} method
*/
public addTransitionHook: Spy<StarkRoutingService["addTransitionHook"]> = createSpy("addTransitionHook");
/**
* See [StarkRoutingService getTranslationKeyFromState()]{@link StarkRoutingService#getTranslationKeyFromState} method
*/
public getTranslationKeyFromState: Spy<StarkRoutingService["getTranslationKeyFromState"]> = createSpy("getTranslationKeyFromState");
}