src/app/tests/mocks/notification.ts
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.');
Properties |
|
Methods |
Accessors |
constructor()
|
Defined in src/app/tests/mocks/notification.ts:29
|
clearAll |
clearAll()
|
Defined in src/app/tests/mocks/notification.ts:52
|
Returns :
void
|
error | ||||||||
error(message?: string)
|
||||||||
Defined in src/app/tests/mocks/notification.ts:39
|
||||||||
Parameters :
Returns :
any
|
info | ||||||||
info(message?: string)
|
||||||||
Defined in src/app/tests/mocks/notification.ts:43
|
||||||||
Parameters :
Returns :
any
|
success | ||||||||
success(message?: string)
|
||||||||
Defined in src/app/tests/mocks/notification.ts:35
|
||||||||
Parameters :
Returns :
any
|
warning | ||||||||
warning(message?: string)
|
||||||||
Defined in src/app/tests/mocks/notification.ts:47
|
||||||||
Parameters :
Returns :
any
|
Private _errorToasts |
_errorToasts:
|
Type : any
|
Defined in src/app/tests/mocks/notification.ts:25
|
Private _infoToasts |
_infoToasts:
|
Type : any
|
Defined in src/app/tests/mocks/notification.ts:29
|
Private _successToasts |
_successToasts:
|
Type : any
|
Defined in src/app/tests/mocks/notification.ts:23
|
Private _warningToasts |
_warningToasts:
|
Type : any
|
Defined in src/app/tests/mocks/notification.ts:27
|
testSuccess |
gettestSuccess()
|
Defined in src/app/tests/mocks/notification.ts:57
|
testError |
gettestError()
|
Defined in src/app/tests/mocks/notification.ts:61
|
testWarning |
gettestWarning()
|
Defined in src/app/tests/mocks/notification.ts:65
|
testInfo |
gettestInfo()
|
Defined in src/app/tests/mocks/notification.ts:69
|
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;
}
}