-
Notifications
You must be signed in to change notification settings - Fork 17
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
Unit testing <Composer> with nested <Fetch> components? #58
Comments
👋 hi @istan ! Thanks for opening this issue. I'm happy to help out, though note that what I'm about to share with you should work, but can probably be improved. Looking at the React Request test suite itself could possibly be useful here, if you haven't already taken a look there. They're not the best tests ever, but they lay out the general strategy I would use. Some general tips I have are:
If your test suite supports it, it could be worthwhile stubbing out the clock, so that you can control how much time is passing, too. By controlling as much as you can (the actual network requests, and possibly the clock), and being conscious of the things that you cannot control (the number of times render is called), you should be able to put together something that works. I'm never 100% happy with unit tests for this sort of things, because, when I write them, they always feel a little bit too brittle for my tastes. I haven't yet had a chance to do this, but I believe that an integration testing approach (something using, say, Puppeteer) would feel less brittle. Oh, also, be sure to switch on async mode in your test suite, so that you control when the test is complete. If you're using Jest, you can do that by including You won't be able to unit test anything involving network requests using the default, synchronous runs of most test suites afaik. |
Thanks! I'm using |
I understand your desire to use the underlying Promise. Right now, that isn’t exposed to consumers by design. I’d consider an API that adds it, though. It would likely need to be behind a flag, like Also, note that I’m planning on a “sequel” library to React Request that solves many of the problems associated with using it, including testability. I’m waiting for some new feature announcements from the React team before i invest the time though ✌️ |
@jamesplease I think that could be pretty helpful, particularly if you provided an example for how to use it. Thanks! |
Hi! Thanks for the great libraries! I'm running into some issues trying to write enzyme unit tests for a component that follows a pattern like this, where
Fetch
comes fromreact-request
:Do you have any examples you can share of how to test this pattern? I seem to be having trouble getting at the underlying promise chain, so my tests complete before
fetchA, fetchB, fetchC
all resolve.Thanks!
The text was updated successfully, but these errors were encountered: