recurly / react-recurly

React components for Recurly.js
MIT License
38 stars 16 forks source link

React Jest unit testing #124

Closed DoryZi closed 9 months ago

DoryZi commented 3 years ago

I'm using React Recurly, it's great stuff :) However in order to run unit tests (jest, react testing library), I must put the script in the html. Jest doesn't seem to offer a simple way to do that, and including the file hosted, doesn't seem to work well either.

How do you suggest someone using recurly.js build unit tests that use the react recurly? Is there a recommended or suggested path for including a js from cdn in jest ?

Please assist this is a blocker for me. Thanks! D.

chrissrogers commented 3 years ago

Good question! For your unit tests, I would consider mocking react-recurly according to your usage. If you're aiming for more of an integration test, you will likely need to go down the path of introducing a real DOM with an html fixture including the recurly.js asset.

We use Jest only for atomic unit tests. If you're looking to perform more of an integration test, I think another tool would be better suited.

DoryZi commented 3 years ago

I see in your unit test there are mocks, I don't mind using those (I would prefer to use the real lib). How can I use those? I mean you guys mock it yourselves, why not expose it ? I would love to use your existing mock than re-invest the wheel? Is that possible?

chrissrogers commented 3 years ago

We mock some underlying dependencies, but don't have a mock implementation that would cover all of react-recurly for use in tests that depend on react-recurly. So my recommendation is that in your test suite, wherever you might invoke react-recurly, to mock those specific invocations.

DoryZi commented 3 years ago

yes but it asks for recurly.js dependecy .. :/

avivshafir commented 3 years ago

+1, same problem in my case, useRecurly in components make it very hard to test not sure how to begin mocking this

jonaseriksson84 commented 2 years ago

I concur, a better way to mock useRecurly would be greatly appreciated.

dkrasnov-aurorasolar commented 6 months ago

was it completed?