Skip to content

test(snackbar): fix tests expectations in dismissal subscription #1664

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 3, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions src/lib/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {
inject,
async,
ComponentFixture,
TestBed
inject,
async,
ComponentFixture,
TestBed,
} from '@angular/core/testing';
import {
NgModule,
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('MdSnackBar', () => {
.toBe('BUTTON', 'Expected snack bar action label to be a <button>');
expect(buttonElement.textContent)
.toBe(simpleActionLabel,
`Expected the snack bar action labe; to be '${simpleActionLabel}'`);
`Expected the snack bar action label to be '${simpleActionLabel}'`);
});

it('should open a simple message with no button', () => {
Expand All @@ -114,25 +114,28 @@ describe('MdSnackBar', () => {
.toBeNull('Expected the query selection for action label to be null');
});

it('should dismiss the snack bar and remove itself from the view', () => {
it('should dismiss the snack bar and remove itself from the view', async(() => {
let config = new MdSnackBarConfig(testViewContainerRef);
let snackBarRef = snackBar.open(simpleMessage, null, config);
let dismissed = true;
snackBarRef.afterDismissed().subscribe(result => {
dismissed = true;
});
let dismissObservableCompleted = false;

let snackBarRef = snackBar.open(simpleMessage, null, config);
viewContainerFixture.detectChanges();
expect(overlayContainerElement.childElementCount)
.toBeGreaterThan(0, 'Expected overlay container element to have at least one child');

snackBarRef.dismiss();
snackBarRef.afterDismissed().subscribe(null, null, () => {
expect(dismissed).toBeTruthy('Expected the snack bar to be dismissed');
dismissObservableCompleted = true;
});

snackBarRef.dismiss();
viewContainerFixture.detectChanges(); // Run through animations for dismissal

viewContainerFixture.whenStable().then(() => {
expect(dismissObservableCompleted).toBeTruthy('Expected the snack bar to be dismissed');
expect(overlayContainerElement.childElementCount)
.toBe(0, 'Expected the overlay container element to have no child elements');
});
});
}));

it('should open a custom component', () => {
let config = new MdSnackBarConfig(testViewContainerRef);
Expand Down Expand Up @@ -166,9 +169,10 @@ describe('MdSnackBar', () => {
});

it(`should set the old snack bar animation state to complete and the new snack bar animation
state to visible on entry of new snack bar`, () => {
state to visible on entry of new snack bar`, async(() => {
let config = new MdSnackBarConfig(testViewContainerRef);
let snackBarRef = snackBar.open(simpleMessage, null, config);
let dismissObservableCompleted = false;

viewContainerFixture.detectChanges();
expect(snackBarRef.containerInstance.animationState)
Expand All @@ -179,12 +183,17 @@ describe('MdSnackBar', () => {

viewContainerFixture.detectChanges();
snackBarRef.afterDismissed().subscribe(null, null, () => {
dismissObservableCompleted = true;
});

viewContainerFixture.whenStable().then(() => {
expect(dismissObservableCompleted).toBe(true);
expect(snackBarRef.containerInstance.animationState)
.toBe('complete', `Expected the animation state would be 'complete'.`);
expect(snackBarRef2.containerInstance.animationState)
.toBe('visible', `Expected the animation state would be 'visible'.`);
});
});
}));
});

@Directive({selector: 'dir-with-view-container'})
Expand Down