Any plans to implement testing utilities?
laurencedorman opened this issue · 6 comments
Just wanted to start a wider discussion on testing Preact components. Is there anything in your roadmap for adding something a bit like React's Simulate?
I understand that there is preact-jsx-chai which is great for testing actual JSX, but what would be the recommended way to go about testing something like the "onClick" of a component unitarily?
Would we have to boot up something with the DOM and simulate actual clicks with a tool like CasperJS?
Or is there something a little lighter that would work?
Currently I use Karma, since there are nice options for result output and it's browser-agnostic. However, I do have some things sitting around relating to mocking out enough of the DOM that Preact boots into DOM mode and can render progressively.
This is something we are working through at Synacor too, so anything that makes life easier would be a huge win.
Do you think it's worth trying to make preact work out of the box with AirBnB's Enzyme? I think in the latest react core notes there was talk of deprecating TestUtils in favor of it.
As for the question about onClick, I actually tend to instantiate the class directly and invoke the method, then assert that the given state mutation as made by spying on setState. It's imperfect, but it avoids needing a DOM.
Thanks, I looked through a few of your example repos to see how you were using Karma and it looks pretty much like it ticks the right boxes. That said, compatibility with Enzyme would be a real plus.
When you talk about instantiating the class, you mean to say you do a new Class()
directly, bypassing all the JSXness?
Yes. I instantiate the classes directly, then can observe the JSX returned from render()
using a sinon mock.
Do you have an example I can look at?
I can certainly write one up, currently they are not open source.
Oh in that case don't trouble yourself, I will RTFM 👍