Skip to content
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
2 changes: 2 additions & 0 deletions src/cdk/testing/testbed/unit-test-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,15 @@ export class UnitTestElement implements TestElement {
/** Hovers the mouse over the element. */
async hover(): Promise<void> {
this._dispatchPointerEventIfSupported('pointerenter');
dispatchMouseEvent(this.element, 'mouseover');
dispatchMouseEvent(this.element, 'mouseenter');
await this._stabilize();
}

/** Moves the mouse away from the element. */
async mouseAway(): Promise<void> {
this._dispatchPointerEventIfSupported('pointerleave');
dispatchMouseEvent(this.element, 'mouseout');
dispatchMouseEvent(this.element, 'mouseleave');
await this._stabilize();
}
Expand Down
8 changes: 6 additions & 2 deletions src/cdk/testing/tests/cross-environment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -468,25 +468,29 @@ export function crossEnvironmentSpecs(
expect(dimensions).toEqual(jasmine.objectContaining({height: 100, width: 200}));
});

it('should be able to hover', async () => {
it('should dispatch `mouseenter` and `mouseover` on hover', async () => {
const box = await harness.hoverTest();
let classAttr = await box.getAttribute('class');
expect(classAttr).not.toContain('hovering');
expect(classAttr).not.toContain('pointer-over');
await box.hover();
classAttr = await box.getAttribute('class');
expect(classAttr).toContain('hovering');
expect(classAttr).toContain('pointer-over');
});

it('should be able to stop hovering', async () => {
it('should dispatch `mouseleave` and `mouseout` on mouseAway', async () => {
const box = await harness.hoverTest();
let classAttr = await box.getAttribute('class');
expect(classAttr).not.toContain('hovering');
await box.hover();
classAttr = await box.getAttribute('class');
expect(classAttr).toContain('hovering');
expect(classAttr).toContain('pointer-over');
await box.mouseAway();
classAttr = await box.getAttribute('class');
expect(classAttr).not.toContain('hovering');
expect(classAttr).not.toContain('pointer-over');
});

it('should be able to getAttribute', async () => {
Expand Down
3 changes: 3 additions & 0 deletions src/cdk/testing/tests/test-main-component.html
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ <h1 style="height: 100px; width: 200px;">Main Component</h1>
<div
id="hover-box"
[class.hovering]="isHovering"
[class.pointer-over]="isPointerOver"
(mouseenter)="isHovering = true"
(mouseleave)="isHovering = false"
(mouseover)="isPointerOver = true"
(mouseout)="isPointerOver = false"
style="width: 50px; height: 50px; background: hotpink;"></div>
<div class="hidden-element" style="display: none;">Hello</div>
1 change: 1 addition & 0 deletions src/cdk/testing/tests/test-main-component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class TestMainComponent implements OnDestroy {
testTools: string[];
testMethods: string[];
isHovering = false;
isPointerOver = false;
specialKey = '';
modifiers: string;
singleSelect: string;
Expand Down