-
Notifications
You must be signed in to change notification settings - Fork 297
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
Make invalid usage of createFetchStore
actions result in Jest test failures as expected
#1801
Comments
@felixarntz regarding this part, I don't think it's necessary that the validation function returns anything, it only needs to throw if something is invalid. I've written the IB accordingly - unless there's another reason why this is needed, I can update it accordingly. |
@aaemnnosttv Mostly LGTM, however one thing to correct I think:
I think this should instead call |
Just wanted to leave this finding here of a similar issue upstream: WordPress/gutenberg#17771 |
This sounds great to finally fix that issue, however we'll need to also still pass After that change the IB should be good to go from my end. |
@felixarntz I've updated the IB to pass both to the internal |
IB ✅ |
Everything looks to be functioning as expected |
Bug Description
With the function signature changes in #1707, we missed quite a few occurrences where these were called but not updated (see #1799), which was fortunately caught before release. The alarming thing is that none of our Jest tests had failed because of that.
A part of that is due to
createFetchStore
not being strict enough. When calling thefetch*
action with invalid arguments, it just usesconsole.error
which will not cause our Jest tests to fail by default. The reason to use console errors was taken only becauseinvariant
wouldn't actually throw errors (which was even the case before switching tocreateFetchStore
). It seems that the way@wordpress/data
works we cannot throw errors from those generator functions?An alternative is that we should possibly change our approach for Jest tests so that any unexpected
console.error
causes a test failure. This may be something we need to do anyway, see #1770.Either way, we should find a way so that such invalid usages make our tests fail.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
createFetchStore
should receive a new argument calledvalidateParams
. The function should receiveparams
and throw on failure (typically viainvariant
). The default should just be an empty function.argsToParams
should be adjusted to no longer include validation.params
should be validated withvalidateParams
for:params
createFetchStore
instances that currently include validation inargsToParams
should move that out of there and instead provide an appropriatevalidateParams
function.Implementation Brief
validateParams
, which defaults to() => {}
invariant
call to ensurevalidateParams
is always a functionrequiresParams
to callvalidateParams
in thetry/catch
validateParams( params )
in thefetchCreator
actiontry/catch
andconsole.error
callsvalidateParams( params )
in thereceiveCreator
action, after theinvariant
call for "params is required"try/catch
andconsole.error
callsvalidateParams( params )
in theisFetching
selector, inside thetry
blockfetchCreator
action to be a normal non-generator functionThis is the main reason why validation is not handled as expected
{ args, params }
) and returned by thefetchCreator
Only
params
is currently needed, butargs
will be needed by changes coming in Implement more appropriate error handling in JS data stores and refactored components #1814 so we can pass both, even though only one is currently needed.args.argsToParams
to only be passed ifparams
are neededargs.validateParams
createFetchStore
usage to moveinvariant
calls into the newvalidateParams
function argCurrently 20 instances
Mostly just needs existing usage updated
QA Brief
Changelog entry
The text was updated successfully, but these errors were encountered: