-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Block Editor: Flatten LinkControl components by mocking useSelect for tests #19705
Conversation
import { fauxEntitySuggestions, fetchFauxEntitySuggestions } from './fixtures'; | ||
|
||
const mockFetchSearchSuggestions = jest.fn(); | ||
|
||
jest.mock( '@wordpress/data', () => { |
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.
👍
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.
I'm pretty sure we do requireActual( "@wordpress/*" )
for other packages. I wonder if it's broken there as well or if it works only for some packages.
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.
I'm pretty sure we do
requireActual( "@wordpress/*" )
for other packages. I wonder if it's broken there as well or if it works only for some packages.
Yeah, I didn't actually look in to it too much, but it was resolving to something, it just seemed it have been not the intended import file (from npm vs. from working directory? src vs. build vs. build-module?). I/we should probably do more to understand what's actually happening.
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.
Thanks for fixing that.
Interesting build failure:
I don't see it locally. But clearly related to the changes here. I'll dig into it. |
Ah, I think as written, the tests assume to resolve from the built file, but we don't require that these exist for running the tests (the tests do their own transpilation via I'll see what can be done about getting it to work with resolving from source like it should be expecting to. |
I expect d66a4ce should pass. I'm not entirely happy with it as a solution, but there's definitely something strange happening when trying to mock the top-level module. I think it may have something to do with the specific way we export modules from this file ( Jest reports a different result of
I also tried a few suggestions from jestjs/jest#936 and the documentation for |
@youknowriad Am I correct in thinking that I'd read a comment from you that And as such, I was going to remove the reference to it in the documentation: But now that I look more closely, I see that in the previous implementation, a custom With the changes in this pull request, it's no longer received as a prop. While all the tests passed, I'll want to double-check that we're not using it anywhere, in case I might have caused a regression. But do you think it's a prop we'd want anyways? |
Follow-up at #19710 |
@aduth correct, I removed it explicitly. My thinking was that for the "block-editor" version of LinkControl, there's no need for this prop and I believe it was there essentially for tests. If we decide later to have a UI version of LinkControl in "components" package, we could bring it back. |
Previously: https://github.com/WordPress/gutenberg/pull/19638/files#r366440796
This pull request seeks to flatten the
LinkControl
component to remove the wrapper component added in #19638 which had been used for the purpose of preserving test behavior. The changes here resolve this by providing a mock for theuseSelect
function in the tests.Testing Instructions:
Ensure unit tests pass: