From b09871acd53018fbc44ba7fa53f98320cb6bed06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Sun, 21 Feb 2021 20:52:48 +0100 Subject: [PATCH] fix(realTouch): accept 0 on x/y axes --- cypress/integration/touch.spec.ts | 13 +++++++++++++ src/commands/realTouch.ts | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cypress/integration/touch.spec.ts b/cypress/integration/touch.spec.ts index bdbd9f4..ec705aa 100644 --- a/cypress/integration/touch.spec.ts +++ b/cypress/integration/touch.spec.ts @@ -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 }); + }); }); diff --git a/src/commands/realTouch.ts b/src/commands/realTouch.ts index 25d4f4d..387663f 100644 --- a/src/commands/realTouch.ts +++ b/src/commands/realTouch.ts @@ -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' + ? { x: options.x || 0, y: options.y || 0 } : options.position; const radiusX = options.radiusX || options.radius || 1 const radiusY = options.radiusY || options.radius || 1