React Fragments have UNDEFINED types in snapshots
See original GitHub issueDo you want to request a feature or report a bug? Bug
What is the current behavior?
When using a snapshot test with a React Fragment The snapshot has UNDEFINED
as node types.
If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install
and yarn test
.
For example:
import React from 'react';
it('doesnt render Unknown for React Fragments', () => {
expect(
<React.Fragment>
<span>Hello World</span>
</React.Fragment>,
).toMatchSnapshot();
});
Generates this snapshot:
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`doesnt render Unknown for React Fragments 1`] = `
<UNDEFINED>
<span>
Hello World
</span>
</UNDEFINED>
`;
Here is an example repo: https://github.com/adriantoine/jest-fragment-bug (note that it’s not using Enzyme or enzyme-to-json, only Jest).
What is the expected behavior?
It renders the Fragment node with the <React.Fragment>...</React.Fragment>
type or an empty node type as it is possible with Babel (<>...</>
).
Please provide your exact Jest configuration It is in the example repo above and it is reproduceable with any config.
Run npx envinfo --preset jest
in your project directory and paste the
results here
System:
OS: macOS High Sierra 10.13.1
CPU: x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
Binaries:
Node: 9.7.1
Yarn: 1.5.1
npm: 5.7.1
npmPackages:
jest:
wanted: ^22.4.2
installed: 22.4.2
If you think that is an issue, I’m happy to look at a fix in pretty-format
although we need to agree if it should be rendered as <React.Fragment>...</React.Fragment>
or <>...</>
.
Thanks!
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:11 (4 by maintainers)
Top GitHub Comments
Fix should be here: https://github.com/facebook/jest/blob/84b17fb59c1d9fd7f964b5f2bfd9d7e2b898f89a/packages/pretty-format/src/plugins/react_element.js#L34-L42
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.