Skip to content

Commit 2c88e9b

Browse files
authored
test: Convert some material tests to zoneless (angular#29309)
1 parent 8ab3642 commit 2c88e9b

File tree

12 files changed

+447
-156
lines changed

12 files changed

+447
-156
lines changed

src/material/core/ripple/ripple.spec.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,6 @@ describe('MatRipple', () => {
286286
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(0);
287287
});
288288

289-
it('does not run events inside the NgZone', () => {
290-
const spy = jasmine.createSpy('zone unstable callback');
291-
const subscription = fixture.ngZone!.onUnstable.subscribe(spy);
292-
293-
dispatchMouseEvent(rippleTarget, 'mousedown');
294-
dispatchMouseEvent(rippleTarget, 'mouseup');
295-
296-
expect(spy).not.toHaveBeenCalled();
297-
subscription.unsubscribe();
298-
});
299-
300289
it('should only persist the latest ripple on pointer down', () => {
301290
dispatchMouseEvent(rippleTarget, 'mousedown');
302291
expect(rippleTarget.querySelectorAll('.mat-ripple-element').length).toBe(1);
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import {dispatchMouseEvent} from '@angular/cdk/testing/private';
2+
import {Component, ViewChild} from '@angular/core';
3+
import {ComponentFixture, TestBed} from '@angular/core/testing';
4+
import {MatRippleModule} from '.';
5+
import {MatRipple} from './ripple';
6+
7+
describe('MatRipple Zone.js integration', () => {
8+
let fixture: ComponentFixture<any>;
9+
let rippleTarget: HTMLElement;
10+
let originalBodyMargin: string | null;
11+
12+
beforeEach(() => {
13+
TestBed.configureTestingModule({
14+
imports: [MatRippleModule, BasicRippleContainer],
15+
});
16+
});
17+
18+
beforeEach(() => {
19+
// Set body margin to 0 during tests so it doesn't mess up position calculations.
20+
originalBodyMargin = document.body.style.margin;
21+
document.body.style.margin = '0';
22+
});
23+
24+
afterEach(() => {
25+
document.body.style.margin = originalBodyMargin!;
26+
});
27+
28+
describe('basic ripple', () => {
29+
beforeEach(() => {
30+
fixture = TestBed.createComponent(BasicRippleContainer);
31+
fixture.detectChanges();
32+
33+
rippleTarget = fixture.nativeElement.querySelector('.mat-ripple');
34+
});
35+
36+
it('does not run events inside the NgZone', () => {
37+
const spy = jasmine.createSpy('zone unstable callback');
38+
const subscription = fixture.ngZone!.onUnstable.subscribe(spy);
39+
40+
dispatchMouseEvent(rippleTarget, 'mousedown');
41+
dispatchMouseEvent(rippleTarget, 'mouseup');
42+
43+
expect(spy).not.toHaveBeenCalled();
44+
subscription.unsubscribe();
45+
});
46+
});
47+
});
48+
49+
@Component({
50+
template: `
51+
<div id="container" #ripple="matRipple" matRipple
52+
style="position: relative; width:300px; height:200px;">
53+
</div>
54+
`,
55+
standalone: true,
56+
imports: [MatRippleModule],
57+
})
58+
class BasicRippleContainer {
59+
@ViewChild('ripple') ripple: MatRipple;
60+
}

0 commit comments

Comments
 (0)