File

testing/src/message-pane.mock.ts

Description

Mock class of the StarkMessagePaneService interface.

Implements

SpyObj

Index

Properties

Properties

Public add
Type : Spy<>
Default value : createSpy("add")
Public addOne
Type : Spy<>
Default value : createSpy("addOne")
Public clearAll
Type : Spy<>
Default value : createSpy("clearAll")
Public clearOnNavigation
Default value : false

See StarkMessagePaneService clearOnNavigation property

Default: false.

Public getAll
Type : Spy<>
Default value : createSpy("getAll")
Public remove
Type : Spy<>
Default value : createSpy("remove")

Usage

The mock class MockStarkMessagePaneService can be imported as follows:

Example :
import { MockStarkMessagePaneService } 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_MESSAGE_PANE_SERVICE, useValue: new MockStarkMessagePaneService() },
        ...
    ]
});

Then you can just inject the Stark service via the TestBed using its corresponding InjectionToken:

Example :
// this will inject the instantiated mock class
mockStarkMessagePaneService = TestBed.inject(STARK_MESSAGE_PANE_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 :
// reading a value
const shouldBeClearedOnNavigation = mockStarkMessagePaneService.clearOnNavigation;

// returning custom value
mockStarkMessagePaneService.getAll.and.returnValue(someCustomObservable);

// overriding a method with a custom function
mockStarkMessagePaneService.add.and.callFake((messages: StarkMessage[]) => {
  // some custom logic to add the messages
});

// asserting that a method was indeed called
expect(mockStarkMessagePaneService.add).toHaveBeenCalledTimes(1);

import { StarkMessagePaneService } from "@nationalbankbelgium/stark-ui";
import Spy = jasmine.Spy;
import SpyObj = jasmine.SpyObj;
import createSpy = jasmine.createSpy;

/**
 * Mock class of the {@link StarkMessagePaneService} interface.
 */
export class MockStarkMessagePaneService implements SpyObj<StarkMessagePaneService> {
	/**
	 * See [StarkMessagePaneService clearOnNavigation]{@link StarkMessagePaneService#clearOnNavigation} property
	 *
	 * Default: `false`.
	 */
	public clearOnNavigation = false;

	/**
	 * See [StarkMessagePaneService add()]{@link StarkMessagePaneService#add} method
	 */
	public add: Spy<StarkMessagePaneService["add"]> = createSpy("add");

	/**
	 * See [StarkMessagePaneService addOne()]{@link StarkMessagePaneService#addOne} method
	 */
	public addOne: Spy<StarkMessagePaneService["addOne"]> = createSpy("addOne");

	/**
	 * See [StarkMessagePaneService getAll()]{@link StarkMessagePaneService#getAll} method
	 */
	public getAll: Spy<StarkMessagePaneService["getAll"]> = createSpy("getAll");

	/**
	 * See [StarkMessagePaneService remove()]{@link StarkMessagePaneService#remove} method
	 */
	public remove: Spy<StarkMessagePaneService["remove"]> = createSpy("remove");

	/**
	 * See [StarkMessagePaneService clearAll()]{@link StarkMessagePaneService#clearAll} method
	 */
	public clearAll: Spy<StarkMessagePaneService["clearAll"]> = createSpy("clearAll");
}

results matching ""

    No results matching ""