-
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
DataForm: add unit tests #68054
DataForm: add unit tests #68054
Conversation
a42b3c4
to
bc4b839
Compare
packages/dataviews/tsconfig.json
Outdated
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 copied pasted the changes from
{ |
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Flaky tests detected in 238f654. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12391474800
|
it( 'should display fields', () => { | ||
render( | ||
<Dataform | ||
onChange={ () => void 0 } |
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.
Why not just using () => {}
as a noop? The void
operator is not very common in our codebase.
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.
It makes sense. Fixed with 238f654.
it( 'should wrap fields in HStack when labelPosition is set to side', async () => { | ||
const { container } = render( | ||
<Dataform | ||
onChange={ () => void 0 } | ||
fields={ fields } | ||
form={ { ...form, labelPosition: 'side' } } | ||
data={ data } | ||
/> | ||
); | ||
|
||
expect( | ||
// It is used here to ensure that the fields are wrapped in HStack. This happens when the labelPosition is set to side. | ||
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access | ||
container.querySelectorAll( "[data-wp-component='HStack']" ) | ||
).toHaveLength( 3 ); | ||
} ); |
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 kind test is too implementation-specific in my view. We're testing a specific HTML output that we may need to change. Personally, I find tests more useful when they test the API. Don't feel you need to remove it, but I find it a bit fragile.
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.
💯 agree with you, but I didn't find a better way to test this behavior.
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. It'd be great to have some e2e tests for the QuickEdit experiment as well :)
Thanks for the review! I'm going to work on it! Thanks for the feedback! |
What?
PR Description
This PR introduces unit tests for the DataForm component, covering the following use cases:
Also, this PR improves the
tsconfig.json
to ensure that js test files are skipped.Why?
How?
Testing Instructions
Ensure that unit test job is green.
Testing Instructions for Keyboard
Screenshots or screencast