File

testing/src/routing.mock.ts

Description

Mock class of the StarkRoutingService interface.

Implements

SpyObj

Index

Properties

Properties

Public addKnownNavigationRejectionCause
Type : Spy<>
Default value : createSpy( "addKnownNavigationRejectionCause" )
Public addTransitionHook
Type : Spy<>
Default value : createSpy("addTransitionHook")
Public getCurrentState
Type : Spy<>
Default value : createSpy("getCurrentState")
Public getCurrentStateConfig
Type : Spy<>
Default value : createSpy("getCurrentStateConfig")
Public getCurrentStateName
Type : Spy<>
Default value : createSpy("getCurrentStateName")
Public getCurrentStateParams
Type : Spy<>
Default value : createSpy("getCurrentStateParams")
Public getStateConfigByUrlPath
Type : Spy<>
Default value : createSpy("getStateConfigByUrlPath")
Public getStateDeclarationByStateName
Type : Spy<>
Default value : createSpy( "getStateDeclarationByStateName" )
Public getStatesConfig
Type : Spy<>
Default value : createSpy("getStatesConfig")
Public getStateTreeData
Type : Spy<>
Default value : createSpy("getStateTreeData")
Public getStateTreeParams
Type : Spy<>
Default value : createSpy("getStateTreeParams")
Public getStateTreeResolves
Type : Spy<>
Default value : createSpy("getStateTreeResolves")
Public getTranslationKeyFromState
Type : Spy<>
Default value : createSpy("getTranslationKeyFromState")
Public isCurrentUiState
Type : Spy<>
Default value : createSpy("isCurrentUiState")
Public isCurrentUiStateIncludedIn
Type : Spy<>
Default value : createSpy("includesState")
Public navigateTo
Type : Spy<>
Default value : createSpy("navigateTo")
Public navigateToHome
Type : Spy<>
Default value : createSpy("navigateToHome")
Public navigateToPrevious
Type : Spy<>
Default value : createSpy("navigateToPrevious")
Public reload
Type : Spy<>
Default value : createSpy("reload")

Usage

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 = TetBed.get(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:

  • return custom values
  • override a method with a custom function
  • asserting that they are actually called
  • do any other operation than can be performed with an Spy.

For 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");
}

result-matching ""

    No results matching ""