dmtrKovalenko / cypress-real-events

Fire native system events from Cypress.
MIT License
755 stars 67 forks source link

realSwipe - x: 0 or y: 0 is incorrectly rejected as being treated as falsey #641

Closed amoshydra closed 2 months ago

amoshydra commented 6 months ago

Expected

TouchStart and TouchEvent should start at coordinate x: 0 and y: 0 when x: 0 and y: 0 is provided in readSwipe

cy.mount(<Canvas />);

cy
  .get("body")
  .realSwipe("toRight", {
    x: 0,
    y: 0,
  })
;

Current

However when a 0 value is provided to either x or y, position is computed to be undefined as the values are falsey and intepreted as not provided.

https://github.com/dmtrKovalenko/cypress-real-events/blob/8b8a509bb6643c2e0dda93966c219653a53c704a/src/commands/realSwipe.ts#L101-L104

Reproduce:

Reproduce repository: https://github.com/amoshydra/repro-dmtrKovalenko-cypress-real-events-i-swipes/blob/real-swipe-with-x-or-y-be-0/src/components/input/Canvas.cy.tsx

The video preview shows 3 tests with the following calls:

.realSwipe("toRight", {
  x: 0,
  y: 1,
})
.realSwipe("toRight", {
  x: 1,
  y: 0,
})
.realSwipe("toRight", {
  x: 1,
  y: 1,
})

https://github.com/dmtrKovalenko/cypress-real-events/assets/8733840/3e43a617-da2c-4192-8eef-1a5ae75428f3

Possible solution

  1. Actually check if x and y are undefined or 0.
  2. If either x or y is provided, automatically fill the undefined x or y as 0.
  3. options.touchPosition should be used only when both x and y are undefined.

Proposal : https://github.com/dmtrKovalenko/cypress-real-events/pull/642

dmtrKovalenko commented 2 months ago

:tada: This issue has been resolved in version 1.13.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: