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

Q: Is there an agreed upon way to properly test Melody apps? #83

Open
CarsonMcKinstry opened this issue Jan 8, 2019 · 4 comments
Open

Comments

@CarsonMcKinstry
Copy link

Coming from the React world we've got enzyme and react-testing-library to handle doing UI unit tests. Is there any equivalent libraries that allow someone to test interactions with the DOM after mounting a component?

@pago
Copy link
Contributor

pago commented Jan 9, 2019

We have an Enzyme-like library internally which we haven't made generally available yet because we don't use it intensively at the moment. I can prepare a PR in the next couple of days to add the functionality. Would you be able to review it and to evaluate it to see if it will serve your needs?

@CarsonMcKinstry
Copy link
Author

I would be happy to take a look.

@pago pago mentioned this issue Jan 11, 2019
@CarsonMcKinstry
Copy link
Author

CarsonMcKinstry commented Jan 13, 2019

I've been looking over the test utils for the last few days. They seem to be almost exactly what I'm looking for, only thing that's missing is the simulate function, which doesn't do exactly what I was expecting.

Expected Behaviour

using simulate should simulate an event of any type, including events with properties like target.value

Actual Behaviour

uses the Event constructor, which doesn't accept anything other than bubbles, cancelable, or composed as options.

This can be an issue when testing an input event. For others like click or mouseenter, this is fine, but because input events (and for the same reason change, keyup, keydown, etc.) have this target.value property, the Event constructor doesn't work to simulate these events in a consumable way.

Possible Solution

So, looking into how enzyme and react-testing-library handle this, I landed on Kent C. Dodd's dom-testing-library. It exports the fireEvent method, which has the ability to create input events that properly set the value property.

I can open a PR showing how that might work.

@pago
Copy link
Contributor

pago commented Jan 13, 2019

That'd be fantastic!

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

No branches or pull requests

2 participants