File

src/app/tests/mocks/notification.ts

Description

Mock for NotificationService.

Provide mocked service to testbed: const notificationService = new MockNotificationService(); TestBed.configureTestingModule({ providers: [ { provide: NotificationService, useValue: notificationService } ] }).compileComponents();

Then it's possible to access and expect toasts: expect(NotificationService.testSuccess.length).toBe(1); expect(NotificationService.testSuccess).toContain('App info loaded.');

Extends

NotificationService

Example

Index

Properties
Methods
Accessors

Constructor

constructor()

Methods

clearAll
clearAll()
Returns : void
error
error(message?: string)
Parameters :
Name Type Optional Description
message string true
Returns : any
info
info(message?: string)
Parameters :
Name Type Optional Description
message string true
Returns : any
success
success(message?: string)
Parameters :
Name Type Optional Description
message string true
Returns : any
warning
warning(message?: string)
Parameters :
Name Type Optional Description
message string true
Returns : any

Properties

Private _errorToasts
_errorToasts: any
Type : any
Private _infoToasts
_infoToasts: any
Type : any
Private _successToasts
_successToasts: any
Type : any
Private _warningToasts
_warningToasts: any
Type : any

Accessors

testSuccess
gettestSuccess()
testError
gettestError()
testWarning
gettestWarning()
testInfo
gettestInfo()
import { NotificationService } from '../../shared/services/notification.service';

/**
 * Mock for NotificationService.
 *
 * Provide mocked service to testbed:
 * const notificationService = new MockNotificationService();
 * TestBed.configureTestingModule({
 *   providers: [
 *     { provide: NotificationService, useValue: notificationService }
 *   ]
 * }).compileComponents();
 *
 * Then it's possible to access and expect toasts:
 * expect(NotificationService.testSuccess.length).toBe(1);
 * expect(NotificationService.testSuccess).toContain('App info loaded.');
 *
 * @author Janne Valkealahti
 * @author Damien Vitrac
 */
export class MockNotificationService extends NotificationService {

  private _successToasts: any = [];

  private _errorToasts: any = [];

  private _warningToasts: any = [];

  private _infoToasts: any = [];

  constructor() {
    super(null);
  }

  success(message?: string): any {
    this._successToasts.push(message);
  }

  error(message?: string): any {
    this._errorToasts.push(message);
  }

  info(message?: string): any {
    this._infoToasts.push(message);
  }

  warning(message?: string): any {
    this._warningToasts.push(message);
  }


  clearAll() {
    this._successToasts.length = 0;
    this._errorToasts.length = 0;
  }

  get testSuccess() {
    return this._successToasts;
  }

  get testError() {
    return this._errorToasts;
  }

  get testWarning() {
    return this._warningToasts;
  }

  get testInfo() {
    return this._infoToasts;
  }

}

results matching ""

    No results matching ""