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: default x y to 0 when not provided, accept 0 value #642

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

amoshydra
Copy link

@amoshydra amoshydra commented Feb 24, 2024

Note to maintainer: Feel free to modify on top of this PR

Summary

Accept 0 for x and y by checking if the value provided is falsey using == null.

   const position =
-    options.x && options.y
+    options.x == null && options.y == null
       ? { x: options.x, y: options.y }
       : options.touchPosition;

If either x or y is provided, prefill the undefined y or x with 0

   const position =
     options.x == null && options.y == null
-      ? { x: options.x, y: options.y }
+      ? { x: options.x || 0, y: options.y || 0 }
       : options.touchPosition;

This is necessary also as Position require both x and y to be defined:

https://github.com/amoshydra/cypress-real-events/blob/d2c3caa0b3ed73109db04b984d8257a0b653f3a1/src/getCypressElementCoordinates.ts#L1-L11

Related issue

This should resolve #641

Motivation

To allow realSwipe to start at x: 0, y: 0

Copy link

what-the-diff bot commented Feb 24, 2024

PR Summary

  • Enhanced Handling for Position Variable in realSwipe Command
    In the realSwipe command, improvements have been made to accommodate scenarios where the x and y options are not assigned any value. This ensures the command performs consistently in varied use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

realSwipe - x: 0 or y: 0 is incorrectly rejected as being treated as falsey
1 participant