|
8 | 8 | } from '@angular/core/testing';
|
9 | 9 | import {Component, ElementRef, ViewChild} from '@angular/core';
|
10 | 10 | import {By} from '@angular/platform-browser';
|
11 |
| -import {NoopAnimationsModule} from '@angular/platform-browser/animations'; |
| 11 | +import {BrowserAnimationsModule, NoopAnimationsModule} from '@angular/platform-browser/animations'; |
12 | 12 | import {MatDrawer, MatSidenavModule, MatDrawerContainer} from './index';
|
13 | 13 | import {A11yModule} from '@angular/cdk/a11y';
|
14 | 14 | import {PlatformModule} from '@angular/cdk/platform';
|
@@ -139,6 +139,7 @@ describe('MatDrawer', () => {
|
139 | 139 | expect(testComponent.openCount).toBe(0);
|
140 | 140 | expect(testComponent.closeCount).toBe(0);
|
141 | 141 |
|
| 142 | + tick(); |
142 | 143 | fixture.debugElement.query(By.css('.close')).nativeElement.click();
|
143 | 144 | fixture.detectChanges();
|
144 | 145 |
|
@@ -368,6 +369,37 @@ describe('MatDrawer', () => {
|
368 | 369 |
|
369 | 370 | expect(fixture.componentInstance.isOpen).toBe(true);
|
370 | 371 | }));
|
| 372 | + |
| 373 | + it('should not throw when a two-way binding is toggled quickly while animating', |
| 374 | + fakeAsync(() => { |
| 375 | + TestBed |
| 376 | + .resetTestingModule() |
| 377 | + .configureTestingModule({ |
| 378 | + imports: [MatSidenavModule, BrowserAnimationsModule], |
| 379 | + declarations: [DrawerOpenBinding], |
| 380 | + }) |
| 381 | + .compileComponents(); |
| 382 | + |
| 383 | + const fixture = TestBed.createComponent(DrawerOpenBinding); |
| 384 | + fixture.detectChanges(); |
| 385 | + |
| 386 | + // Note that we need actual timeouts and the `BrowserAnimationsModule` |
| 387 | + // in order to test it correctly. |
| 388 | + setTimeout(() => { |
| 389 | + fixture.componentInstance.isOpen = !fixture.componentInstance.isOpen; |
| 390 | + expect(() => fixture.detectChanges()).not.toThrow(); |
| 391 | + |
| 392 | + setTimeout(() => { |
| 393 | + fixture.componentInstance.isOpen = !fixture.componentInstance.isOpen; |
| 394 | + expect(() => fixture.detectChanges()).not.toThrow(); |
| 395 | + }, 1); |
| 396 | + |
| 397 | + tick(1); |
| 398 | + }, 1); |
| 399 | + |
| 400 | + tick(1); |
| 401 | + })); |
| 402 | + |
371 | 403 | });
|
372 | 404 |
|
373 | 405 | describe('focus trapping behavior', () => {
|
@@ -512,6 +544,7 @@ describe('MatDrawerContainer', () => {
|
512 | 544 |
|
513 | 545 | fixture.componentInstance.renderDrawer = false;
|
514 | 546 | fixture.detectChanges();
|
| 547 | + tick(); |
515 | 548 |
|
516 | 549 | expect(parseInt(contentElement.style.marginLeft)).toBeLessThan(initialMargin);
|
517 | 550 | }));
|
|
0 commit comments