-
Notifications
You must be signed in to change notification settings - Fork 48
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
Is there a method similar with fetchMock.flush? #102
Comments
There isn't a similar method at the moment but it sounds like a feature that could be implemented. Could you please provide me with a code example of how you'd use it? Is this for testing a component render? |
I'm writing UT for React components which mostly do an HTTP request after mounted. I need to check the state of components after the request was finished. Without the |
Thanks for explaining it in more detail! Could you please you provide a minimal code example that demonstrates how the feature should work which we can use as a test? |
I'm not sure the code is runnable... |
BTW, Is there a hacky and easy way to meet my requirements? I tried to modify the XMLHttpRequest and could not find a way to wrap the process into a Promise object. |
An API "wait for all" in As long as there is no API for this, you can use your own promises to wait just for the calls that you need. (If the mock was called multiple times, or if it was in other script as a shared utility, you could use an event emitter instead of the promise to inform the test about the finished request.) For example: let respond;
const responded = new Promise(resolve => (respond = resolve));
xhrMock.get('/count', (request, response) => {
// switch context to let the component update by the promise
setTimeout(respond);
return response.status(200).body(1);
});
const wrapper = mount(
<TestComp />
);
await responded;
expect(wrapper.state('count')).to.be.equal(1); Alternatively, you could try watching for updates of the |
@SunnyWind I don't believe there's an easy way to implement the functionality in the current version ( |
I was thinking the @prantlf What would the API for a scope object look like? Can you provide a theoretical example? Thanks for the interim work around! *I'm keen to hear people's opinion on the method name! e.g. |
The method description is as follows:
The text was updated successfully, but these errors were encountered: