File

testing/src/progress-indicator.mock.ts

Description

Mock class of the StarkProgressIndicatorService interface.

Implements

SpyObj

Index

Properties

Properties

Public deregister
Type : Spy<>
Default value : createSpy("deregister")
Public hide
Type : Spy<>
Default value : createSpy("hide")
Public isVisible
Type : Spy<>
Default value : createSpy("isVisible")
Public register
Type : Spy<>
Default value : createSpy("register")
Public show
Type : Spy<>
Default value : createSpy("show")

Usage

The mock class MockStarkProgressIndicatorService can be imported as follows:

Example :
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:

Example :
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:

Example :
// 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:

  • 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:

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

results matching ""

    No results matching ""