-
Notifications
You must be signed in to change notification settings - Fork 47.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
Convert elements to test objects for toMatchObject in Jest #9747
Comments
Thanks for the proposal @pedrottimark! The test renderer recently got a new API, Could this be implemented in user-land using this API? Looking at your draft it seems like it might be pretty straightforward. |
@aweary Thank you for link to PR for the Because this proposed use of As you say, The reason to support in The solution seems like more diplomacy than technology, because the problem appears in Jest or AVA, but the remaining work is in other packages. Y’all won’t hurt my feelings, if the team needs to close this issue to focus on finishing Fiber. |
My hunch is this should be first built in userland. If it works well and people use it successfully we can consider reopening this and bringing it into the test renderer. |
Do you want to request a feature or report a bug?
Request your guidance to add a feature for testing, especially with Jest and Enzyme
What is the current behavior?
To get the benefit of descriptive JSX you must pay a cost of irrelevant details in some snapshot tests, which cause unnecessary updates, and risk incorrect decisions.
What is the proposed behavior?
Goal: balance effort to write tests initially and update tests correctly when components change.
Replace some
toMatchSnapshot
withtoMatchObject
for elements with a relevant subset of props.Therefore, this issue to convert the expected React elements directly to test objects, especially for shallow rendering and a new deep-event/shallow-test pattern (see Table-C example).
For more information, see:
Proposed: be able to import from
react-test-renderer
irrelevant
String sentinel value to ignore children, or absence of children, in received objectrelevantTestObject
Given a React element, return the unrendered element as a test object:$$typeof
is enumerable, see toMatchObject diff displays Received from react-test-renderer as Object instead of JSX jestjs/jest#2351props
is omitted if there are no properties, not includingchildren
children
is omitted if it is[irrelevant]
Can you think of clearer names? I am willing to contribute with your guidance.
Draft of code: https://github.com/pedrottimark/whimper/blob/master/src/testing/react-test-renderer/relevantTestObject.js
Because
toMatchObject
expects an object,relevantTestObject
doesn’t expect an array of elements, which components can render in React 16. Can you think of test cases when it should?Examples of tests:
mountToDeepJson
in https://github.com/pedrottimark/whimper/blob/master/src/components/__tests__/Table-U.test.jsmountToShallowJson
viatbodyShallow
in https://github.com/pedrottimark/whimper/blob/master/src/components/__tests__/Table-C.test.js and so onThe text was updated successfully, but these errors were encountered: