-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add tests for refx REQUEST_POST_UPDATE effects network requests. #966
Conversation
5701d49
to
f7d1906
Compare
eddb348
to
07128b9
Compare
editor/test/effects.js
Outdated
const wpApiMockSuccess = { | ||
data: post, | ||
success: false, | ||
Post( args ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should be able to do // eslint-disable-line name-of-the-failing-rule
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition to that, I am not sure whether this is a good approach for mocking the wp.api
stuff. Any improved ideas would be very welcome!
Think I might close this out. It kind of just makes our actual code more complicated than it should be. |
I think we'd want some form of testing here, but I agree network mocking is a bit of a pain. It would be nicer if we could chain effects by dispatching or returning a generic |
Thanks for working on those tests 👍 Another approach to consider would be to stub method calls for whatever |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests depends on chai and sinon. We would have to rewrite them to work with Jest :)
@BE-Webdesign do you plan to take another look at this one?
Yup, eventually I will. I am waiting on the decision of the testing framework before getting back into the tests. |
Cool, thanks for your update. We should know more by the end of tomorrow. I'm betting on Jest after the upcoming relicensing :) |
07128b9
to
a90e537
Compare
Review would be great, this just tests the REQUEST_POST_UPDATE effect. Will make seperate PRs for the other pieces. The tests verify that the proper actions are dispatched under the correct conditions. |
Add tests for the REQUEST_POST_UPDATE effect. These tests mock wp.api to cover potential response values.
a90e537
to
41741a3
Compare
Hey, @BE-Webdesign Good work here. But in general I try to compare the gain we'd have in having tests compared to the burden of maintaining them when adding tests. (I know some people like 100% coverage no matter the complexity of the tests, but I disagree with this approach in general). So I'm wondering here, are these tests useful enough to deserve maintaining these complex tests (hard to follow, mocking api, promises...)? I'm leaning towards avoiding these but happy to be proven wrong. |
As discussed in this week's meeting due to changes in way API requests are called. |
Slack discussion: https://wordpress.slack.com/archives/C02QB2JS7/p1520432967000006 |
A few things: I agree with @youknowriad's concerns at #966 (comment) , and really it speaks to a bigger issue with how we're doing side effects, as they're quite complex and overly convoluted. I think at the very least we should be targeting less the action type which is the source of the effect, and rather the individual behaviors themselves. This may just be extracting functions which are called by the effect. See #5417 as an example. With some of the generalized patterns for network behaviors like explored in #5219, I hope we'll need less of these side effects in general. Finally, with changes in #5253, the mocking here would not need to be adjusted significantly. |
These tests handle the network effects portion of unit testing our refx middleware. This makes use of stubs for testing the history API, and explicitly modifying the window.location object to be writable. For the network effects, these effects are broken out into seperate functions which use partial application to isolate the networkCallback. The postRequest function becomes a wrapper for wp.api.models.Post(). So the API remains consistent. Rather than doing a sinon mock, the wp.api.models.Post interface is manually mocked for easy future changing. As we change the actual implementation of the network requests these tests will fail, which is a good thing. If we use straight mocks we might get false positives instead.
Testing Instructions
Verify Trashing and Saving still works properly. Verify that tests pass.