Skip to content

Commit 3a379b3

Browse files
crisbetojelbourn
authored andcommitted
test: infinite loop in tests (#4662)
Fixes some unit tests going into an infinite loop by using the `jasmine.any` matcher. Not exactly sure what is going on, but it was most likely introduced in Jasmine 2.6.2. For now I've replaced those matches with `instanceof` checks which accomplish the same. Fixes #4654.
1 parent c946631 commit 3a379b3

File tree

5 files changed

+25
-25
lines changed

5 files changed

+25
-25
lines changed

src/lib/core/overlay/overlay-directives.spec.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Overlay directives', () => {
7777

7878
let strategy =
7979
<ConnectedPositionStrategy> overlayDirective.overlayRef.getState().positionStrategy;
80-
expect(strategy).toEqual(jasmine.any(ConnectedPositionStrategy));
80+
expect(strategy instanceof ConnectedPositionStrategy).toBe(true);
8181

8282
let positions = strategy.positions;
8383
expect(positions.length).toBeGreaterThan(0);
@@ -266,9 +266,11 @@ describe('Overlay directives', () => {
266266
fixture.detectChanges();
267267

268268
expect(fixture.componentInstance.positionChangeHandler).toHaveBeenCalled();
269-
expect(fixture.componentInstance.positionChangeHandler.calls.mostRecent().args[0])
270-
.toEqual(jasmine.any(ConnectedOverlayPositionChange),
271-
`Expected directive to emit an instance of ConnectedOverlayPositionChange.`);
269+
270+
const latestCall = fixture.componentInstance.positionChangeHandler.calls.mostRecent();
271+
272+
expect(latestCall.args[0] instanceof ConnectedOverlayPositionChange)
273+
.toBe(true, `Expected directive to emit an instance of ConnectedOverlayPositionChange.`);
272274
});
273275

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

280282
expect(fixture.componentInstance.attachHandler).toHaveBeenCalled();
281-
expect(fixture.componentInstance.attachResult)
282-
.toEqual(jasmine.any(HTMLElement),
283-
`Expected pane to be populated with HTML elements when attach was called.`);
283+
expect(fixture.componentInstance.attachResult instanceof HTMLElement)
284+
.toBe(true, `Expected pane to be populated with HTML elements when attach was called.`);
284285
expect(fixture.componentInstance.detachHandler).not.toHaveBeenCalled();
285286

286287
fixture.componentInstance.isOpen = false;

src/lib/core/overlay/position/connected-position-strategy.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,12 @@ describe('ConnectedPositionStrategy', () => {
336336
const subscription = strategy.onPositionChange.subscribe(positionChangeHandler);
337337

338338
strategy.apply(overlayElement);
339+
340+
const latestCall = positionChangeHandler.calls.mostRecent();
341+
339342
expect(positionChangeHandler).toHaveBeenCalled();
340-
expect(positionChangeHandler.calls.mostRecent().args[0])
341-
.toEqual(jasmine.any(ConnectedOverlayPositionChange),
342-
`Expected strategy to emit an instance of ConnectedOverlayPositionChange.`);
343+
expect(latestCall.args[0] instanceof ConnectedOverlayPositionChange)
344+
.toBe(true, `Expected strategy to emit an instance of ConnectedOverlayPositionChange.`);
343345

344346
it('should pick the fallback position that shows the largest area of the element', () => {
345347
positionBuilder = new OverlayPositionBuilder(viewportRuler);

src/lib/core/portal/portal.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ describe('Portals', () => {
244244

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

247-
expect(componentInstance).toEqual(jasmine.any(PizzaMsg));
247+
expect(componentInstance instanceof PizzaMsg).toBe(true);
248248
expect(someDomElement.textContent).toContain('Pizza');
249249

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

266-
expect(componentInstance).toEqual(jasmine.any(PizzaMsg));
266+
expect(componentInstance instanceof PizzaMsg).toBe(true);
267267
expect(someDomElement.textContent).toContain('Pizza');
268268
expect(someDomElement.textContent).toContain('Chocolate');
269269

@@ -342,8 +342,8 @@ describe('Portals', () => {
342342

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

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

src/lib/dialog/dialog.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('MdDialog', () => {
7272
viewContainerFixture.detectChanges();
7373

7474
expect(overlayContainerElement.textContent).toContain('Pizza');
75-
expect(dialogRef.componentInstance).toEqual(jasmine.any(PizzaMsg));
75+
expect(dialogRef.componentInstance instanceof PizzaMsg).toBe(true);
7676
expect(dialogRef.componentInstance.dialogRef).toBe(dialogRef);
7777

7878
viewContainerFixture.detectChanges();
@@ -101,7 +101,7 @@ describe('MdDialog', () => {
101101
viewContainerFixture.detectChanges();
102102

103103
expect(overlayContainerElement.textContent).toContain('Pizza');
104-
expect(dialogRef.componentInstance).toEqual(jasmine.any(PizzaMsg));
104+
expect(dialogRef.componentInstance instanceof PizzaMsg).toBe(true);
105105
expect(dialogRef.componentInstance.dialogRef).toBe(dialogRef);
106106

107107
viewContainerFixture.detectChanges();

src/lib/snack-bar/snack-bar.spec.ts

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@ describe('MdSnackBar', () => {
8989

9090
viewContainerFixture.detectChanges();
9191

92-
expect(snackBarRef.instance)
93-
.toEqual(jasmine.any(SimpleSnackBar),
94-
'Expected the snack bar content component to be SimpleSnackBar');
92+
expect(snackBarRef.instance instanceof SimpleSnackBar)
93+
.toBe(true, 'Expected the snack bar content component to be SimpleSnackBar');
9594
expect(snackBarRef.instance.snackBarRef)
9695
.toBe(snackBarRef, 'Expected the snack bar reference to be placed in the component instance');
9796

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

114113
viewContainerFixture.detectChanges();
115114

116-
expect(snackBarRef.instance)
117-
.toEqual(jasmine.any(SimpleSnackBar),
118-
'Expected the snack bar content component to be SimpleSnackBar');
115+
expect(snackBarRef.instance instanceof SimpleSnackBar)
116+
.toBe(true, 'Expected the snack bar content component to be SimpleSnackBar');
119117
expect(snackBarRef.instance.snackBarRef)
120118
.toBe(snackBarRef, 'Expected the snack bar reference to be placed in the component instance');
121119

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

183-
expect(snackBarRef.instance)
184-
.toEqual(jasmine.any(BurritosNotification),
185-
'Expected the snack bar content component to be BurritosNotification');
181+
expect(snackBarRef.instance instanceof BurritosNotification)
182+
.toBe(true, 'Expected the snack bar content component to be BurritosNotification');
186183
expect(overlayContainerElement.textContent.trim())
187184
.toBe('Burritos are on the way.',
188185
`Expected the overlay text content to be 'Burritos are on the way'`);

0 commit comments

Comments
 (0)