Skip to content

test: fix infinite loop in tests #4662

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
May 22, 2017
Merged
Show file tree
Hide file tree
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
15 changes: 8 additions & 7 deletions src/lib/core/overlay/overlay-directives.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('Overlay directives', () => {

let strategy =
<ConnectedPositionStrategy> overlayDirective.overlayRef.getState().positionStrategy;
expect(strategy).toEqual(jasmine.any(ConnectedPositionStrategy));
expect(strategy instanceof ConnectedPositionStrategy).toBe(true);

let positions = strategy.positions;
expect(positions.length).toBeGreaterThan(0);
Expand Down Expand Up @@ -266,9 +266,11 @@ describe('Overlay directives', () => {
fixture.detectChanges();

expect(fixture.componentInstance.positionChangeHandler).toHaveBeenCalled();
expect(fixture.componentInstance.positionChangeHandler.calls.mostRecent().args[0])
.toEqual(jasmine.any(ConnectedOverlayPositionChange),
`Expected directive to emit an instance of ConnectedOverlayPositionChange.`);

const latestCall = fixture.componentInstance.positionChangeHandler.calls.mostRecent();

expect(latestCall.args[0] instanceof ConnectedOverlayPositionChange)
.toBe(true, `Expected directive to emit an instance of ConnectedOverlayPositionChange.`);
});

it('should emit attach and detach appropriately', () => {
Expand All @@ -278,9 +280,8 @@ describe('Overlay directives', () => {
fixture.detectChanges();

expect(fixture.componentInstance.attachHandler).toHaveBeenCalled();
expect(fixture.componentInstance.attachResult)
.toEqual(jasmine.any(HTMLElement),
`Expected pane to be populated with HTML elements when attach was called.`);
expect(fixture.componentInstance.attachResult instanceof HTMLElement)
.toBe(true, `Expected pane to be populated with HTML elements when attach was called.`);
expect(fixture.componentInstance.detachHandler).not.toHaveBeenCalled();

fixture.componentInstance.isOpen = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,10 +336,12 @@ describe('ConnectedPositionStrategy', () => {
const subscription = strategy.onPositionChange.subscribe(positionChangeHandler);

strategy.apply(overlayElement);

const latestCall = positionChangeHandler.calls.mostRecent();

expect(positionChangeHandler).toHaveBeenCalled();
expect(positionChangeHandler.calls.mostRecent().args[0])
.toEqual(jasmine.any(ConnectedOverlayPositionChange),
`Expected strategy to emit an instance of ConnectedOverlayPositionChange.`);
expect(latestCall.args[0] instanceof ConnectedOverlayPositionChange)
.toBe(true, `Expected strategy to emit an instance of ConnectedOverlayPositionChange.`);

it('should pick the fallback position that shows the largest area of the element', () => {
positionBuilder = new OverlayPositionBuilder(viewportRuler);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/core/portal/portal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ describe('Portals', () => {

let componentInstance: PizzaMsg = portal.attach(host).instance;

expect(componentInstance).toEqual(jasmine.any(PizzaMsg));
expect(componentInstance instanceof PizzaMsg).toBe(true);
expect(someDomElement.textContent).toContain('Pizza');

host.detach();
Expand All @@ -263,7 +263,7 @@ describe('Portals', () => {
let componentInstance: PizzaMsg = portal.attach(host).instance;
fixture.detectChanges();

expect(componentInstance).toEqual(jasmine.any(PizzaMsg));
expect(componentInstance instanceof PizzaMsg).toBe(true);
expect(someDomElement.textContent).toContain('Pizza');
expect(someDomElement.textContent).toContain('Chocolate');

Expand Down Expand Up @@ -342,8 +342,8 @@ describe('Portals', () => {

let componentInstance: PizzaMsg = portal.attach(host).instance;

expect(componentInstance)
.toEqual(jasmine.any(PizzaMsg), 'Expected a PizzaMsg component to be created');
expect(componentInstance instanceof PizzaMsg)
.toBe(true, 'Expected a PizzaMsg component to be created');
expect(someDomElement.textContent)
.toContain('Pizza', 'Expected the static string "Pizza" in the DomPortalHost.');

Expand Down
4 changes: 2 additions & 2 deletions src/lib/dialog/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('MdDialog', () => {
viewContainerFixture.detectChanges();

expect(overlayContainerElement.textContent).toContain('Pizza');
expect(dialogRef.componentInstance).toEqual(jasmine.any(PizzaMsg));
expect(dialogRef.componentInstance instanceof PizzaMsg).toBe(true);
expect(dialogRef.componentInstance.dialogRef).toBe(dialogRef);

viewContainerFixture.detectChanges();
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('MdDialog', () => {
viewContainerFixture.detectChanges();

expect(overlayContainerElement.textContent).toContain('Pizza');
expect(dialogRef.componentInstance).toEqual(jasmine.any(PizzaMsg));
expect(dialogRef.componentInstance instanceof PizzaMsg).toBe(true);
expect(dialogRef.componentInstance.dialogRef).toBe(dialogRef);

viewContainerFixture.detectChanges();
Expand Down
15 changes: 6 additions & 9 deletions src/lib/snack-bar/snack-bar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ describe('MdSnackBar', () => {

viewContainerFixture.detectChanges();

expect(snackBarRef.instance)
.toEqual(jasmine.any(SimpleSnackBar),
'Expected the snack bar content component to be SimpleSnackBar');
expect(snackBarRef.instance instanceof SimpleSnackBar)
.toBe(true, 'Expected the snack bar content component to be SimpleSnackBar');
expect(snackBarRef.instance.snackBarRef)
.toBe(snackBarRef, 'Expected the snack bar reference to be placed in the component instance');

Expand All @@ -113,9 +112,8 @@ describe('MdSnackBar', () => {

viewContainerFixture.detectChanges();

expect(snackBarRef.instance)
.toEqual(jasmine.any(SimpleSnackBar),
'Expected the snack bar content component to be SimpleSnackBar');
expect(snackBarRef.instance instanceof SimpleSnackBar)
.toBe(true, 'Expected the snack bar content component to be SimpleSnackBar');
expect(snackBarRef.instance.snackBarRef)
.toBe(snackBarRef, 'Expected the snack bar reference to be placed in the component instance');

Expand Down Expand Up @@ -180,9 +178,8 @@ describe('MdSnackBar', () => {
let config = {viewContainerRef: testViewContainerRef};
let snackBarRef = snackBar.openFromComponent(BurritosNotification, config);

expect(snackBarRef.instance)
.toEqual(jasmine.any(BurritosNotification),
'Expected the snack bar content component to be BurritosNotification');
expect(snackBarRef.instance instanceof BurritosNotification)
.toBe(true, 'Expected the snack bar content component to be BurritosNotification');
expect(overlayContainerElement.textContent.trim())
.toBe('Burritos are on the way.',
`Expected the overlay text content to be 'Burritos are on the way'`);
Expand Down