Skip to content

Commit 1f5df66

Browse files
committed
test(toast): refactor tests
1 parent c70a2fb commit 1f5df66

File tree

2 files changed

+51
-29
lines changed

2 files changed

+51
-29
lines changed

projects/igniteui-angular/src/lib/toast/toast.component.spec.ts

Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, ViewChild } from '@angular/core';
22
import {
3-
async,
3+
waitForAsync,
44
TestBed,
55
fakeAsync,
66
tick,
@@ -14,17 +14,16 @@ import {
1414
} from './toast.component';
1515
import { configureTestSuite } from '../test-utils/configure-suite';
1616

17-
describe('IgxToast', () => {
17+
fdescribe('IgxToast', () => {
1818
configureTestSuite();
19-
beforeAll(async(() => {
19+
beforeAll(waitForAsync(() => {
2020
TestBed.configureTestingModule({
2121
declarations: [ToastInitializeTestComponent],
2222
imports: [BrowserAnimationsModule, IgxToastModule],
2323
}).compileComponents();
2424
}));
2525

2626
const baseClass = 'igx-toast';
27-
const activeClass = 'igx-toast--active';
2827
let fixture: ComponentFixture<ToastInitializeTestComponent>;
2928
let toast: IgxToastComponent;
3029

@@ -43,7 +42,6 @@ describe('IgxToast', () => {
4342
expect(toast.displayTime).toBe(4000);
4443
expect(toast.autoHide).toBeTruthy();
4544
expect(toast.isVisible).toBeTruthy();
46-
expect(domToast.classList).toContain(activeClass);
4745

4846
toast.id = 'customToast';
4947
fixture.detectChanges();
@@ -79,28 +77,52 @@ describe('IgxToast', () => {
7977
expect(toast.isVisible).toBeTruthy();
8078
}));
8179

82-
it('visibility is updated by the toggle() method', () => {
83-
spyOn(toast.onShowing, 'emit');
84-
spyOn(toast.onShown, 'emit');
85-
spyOn(toast.onHiding, 'emit');
86-
spyOn(toast.onHidden, 'emit');
80+
it('should emit onShowing when super onOpening is fired', waitForAsync(() => {
81+
toast.show();
82+
83+
toast.onOpening.subscribe(() => {
84+
spyOn(toast.onShowing, 'emit');
85+
expect(toast.onShowing.emit).toHaveBeenCalled();
86+
});
87+
}));
8788

89+
it('should emit onShown when super onAppended is fired', waitForAsync(() => {
8890
toast.show();
89-
expect(toast.isVisible).toBe(true);
9091

91-
expect(toast.onShowing.emit).toHaveBeenCalledTimes(1);
92-
expect(toast.onShown.emit).toHaveBeenCalledTimes(1);
93-
expect(toast.onHiding.emit).toHaveBeenCalledTimes(0);
94-
expect(toast.onHidden.emit).toHaveBeenCalledTimes(0);
92+
toast.onAppended.subscribe(() => {
93+
spyOn(toast.onShown, 'emit');
94+
expect(toast.onShown.emit).toHaveBeenCalled();
95+
});
96+
}));
97+
98+
it('should emit onHiding when super onClosing is fired', waitForAsync(() => {
99+
toast.isVisible = true;
100+
toast.hide();
101+
102+
toast.onClosing.subscribe(() => {
103+
spyOn(toast.onHiding, 'emit');
104+
expect(toast.onHiding.emit).toHaveBeenCalled();
105+
});
106+
}));
95107

108+
it('should emit onHidden when super onClosed is fired', waitForAsync(() => {
109+
toast.isVisible = true;
110+
toast.hide();
111+
112+
toast.onClosed.subscribe(() => {
113+
spyOn(toast.onHidden, 'emit');
114+
expect(toast.onHidden.emit).toHaveBeenCalled();
115+
});
116+
}));
117+
118+
it('visibility is updated by the toggle() method', waitForAsync(() => {
119+
toast.isVisible = true;
96120
toast.toggle();
97-
expect(toast.isVisible).toBe(false);
98121

99-
expect(toast.onShowing.emit).toHaveBeenCalledTimes(1);
100-
expect(toast.onShown.emit).toHaveBeenCalledTimes(1);
101-
expect(toast.onHiding.emit).toHaveBeenCalledTimes(1);
102-
expect(toast.onHidden.emit).toHaveBeenCalledTimes(1);
103-
});
122+
toast.onHiding.subscribe(() => {
123+
expect(toast.isVisible).toEqual(false);
124+
});
125+
}));
104126

105127
it('can set message through show method', fakeAsync(() => {
106128
toast.displayTime = 100;

projects/igniteui-angular/src/lib/toast/toast.component.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ export class IgxToastComponent extends IgxToggleDirective
262262
* @memberof IgxToastComponent
263263
*/
264264
public get element() {
265-
return this._element.nativeElement;
265+
return this.element.nativeElement;
266266
}
267267

268268
/**
@@ -277,7 +277,7 @@ export class IgxToastComponent extends IgxToggleDirective
277277
private timeoutId: number;
278278

279279
constructor(
280-
private _element: ElementRef,
280+
_element: ElementRef,
281281
cdr: ChangeDetectorRef,
282282
@Optional() navService: IgxNavigationService,
283283
@Inject(IgxOverlayService) overlayService: IgxOverlayService
@@ -321,17 +321,17 @@ export class IgxToastComponent extends IgxToggleDirective
321321
this.onShowing.emit(this);
322322
});
323323

324+
this.onAppended.subscribe(() => {
325+
this.onShown.emit(this);
326+
});
327+
328+
super.open(overlaySettings);
329+
324330
if (this.autoHide) {
325331
this.timeoutId = window.setTimeout(() => {
326332
this.hide();
327333
}, this.displayTime);
328334
}
329-
330-
super.open(overlaySettings);
331-
332-
this.onOpened.subscribe(() => {
333-
this.onShown.emit(this);
334-
});
335335
}
336336

337337
/**

0 commit comments

Comments
 (0)