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

onBegin not called when fromData invoked #82

Closed
AndrewOttavianoAbb opened this issue Jun 3, 2022 · 1 comment
Closed

onBegin not called when fromData invoked #82

AndrewOttavianoAbb opened this issue Jun 3, 2022 · 1 comment
Labels
kind: support Asking for support with something or a specific use case scope: upstream Issue in upstream dependency solution: intended behavior This is not a bug and is expected behavior

Comments

@AndrewOttavianoAbb
Copy link

AndrewOttavianoAbb commented Jun 3, 2022

I am trying to test some buttons that I am enabling when onBegin is called. My problem is that it is generally quite difficult to make a test runner scribble a line across the canvas. To get around this, I attempted to use fromData as done in this repository's tests thinking that if data was added to the canvas, surely onBegin would be called.

So I'm logging this issue because of my testing issue but also thought it kind of weird that onBegin isn't called and was curious about the reasoning behind that. Also would appreciate any advice on how to test my onBegin handler 😉

@agilgur5 agilgur5 added scope: upstream Issue in upstream dependency solution: intended behavior This is not a bug and is expected behavior kind: support Asking for support with something or a specific use case labels Jun 3, 2022
@agilgur5
Copy link
Owner

agilgur5 commented Jun 4, 2022

but also thought it kind of weird that onBegin isn't called and was curious about the reasoning behind that.

Per the description of this library, it is but a wrapper around signature_pad, so this behavior is entirely controlled by signature_pad. You'll also notice that the tests and source code don't mention onBegin as it's just passed through to the signature_pad instance directly (that will change slightly with signature_pad v4 though, per #68).

So this kind of question really belongs upstream rather than here, although support questions are generally discouraged from issues by volunteer maintainers; StackOverflow etc exist for that.

I can only speculate as to why, but I do believe not calling event handlers on fromData makes sense. onBegin etc are explicitly defined as mouse event handlers, so one could very well consider it erroneous behavior if they were called during fromData, as no mouse event occurred.
As fromData is also an instance method, that means the developer (not the end-user) called it and so the developer could also feed the data into their own callbacks directly if they so desired.

Also would appreciate any advice on how to test my onBegin handler 😉

I was able to workaround this in the test suite here as react-signature-canvas just passes the handlers through, but I remember thinking about this issue too (also for trim-canvas's test suite in agilgur5/trim-canvas#9).
Back then I was imagining simulating clicks on the canvas. I believe one click should be enough to generate data.

I'm not sure if that'll work within the confines of jsdom / node-canvas (I haven't tried), but if not, can try @jest-runner/electron or Cypress if a real browser is needed. I have some comparisons in a different library of mine here: agilgur5/physijs-webpack#15 / agilgur5/physijs-webpack#16 (I prefer the former, which sometimes even has better performance than jsdom too)

@agilgur5 agilgur5 closed this as completed Jun 4, 2022
Repository owner locked as resolved and limited conversation to collaborators Jun 17, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind: support Asking for support with something or a specific use case scope: upstream Issue in upstream dependency solution: intended behavior This is not a bug and is expected behavior
Projects
None yet
Development

No branches or pull requests

2 participants