Skip to content
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

fix(realTouch): accept 0 on x/y axes #33

Merged
merged 1 commit into from
Feb 24, 2021
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
13 changes: 13 additions & 0 deletions cypress/integration/touch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,17 @@ describe("cy.realTouch", () => {
})
.realTouch({ radiusX: 5, radiusY: 7 });
});

it("touches using provided 0 for one of the axis", (done) => {
cy.get(".action-btn")
.then(($button) => {
$button.get(0).addEventListener("pointerdown", (event) => {
const rect = (event.currentTarget as HTMLElement).getBoundingClientRect()
expect(event.clientX).to.be.closeTo(rect.left - 5, 0.1);
expect(event.clientY).to.be.closeTo(rect.top, 0.1);
done();
});
})
.realTouch({ x: -5, y: 0, radius: 10 });
});
});
4 changes: 2 additions & 2 deletions src/commands/realTouch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export async function realTouch(
subject: JQuery,
options: RealTouchOptions = {}
) {
const position = options.x && options.y
? { x: options.x, y: options.y }
const position = typeof options.x === 'number' || typeof options.y === 'number'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO || makes sense over && here as JSDoc states that:

X coordinate to click, relative to the Element. Overrides position.

/** X coordinate to click, relative to the Element. Overrides `position`.

? { x: options.x || 0, y: options.y || 0 }
: options.position;
const radiusX = options.radiusX || options.radius || 1
const radiusY = options.radiusY || options.radius || 1
Expand Down