question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Fragments have UNDEFINED types in snapshots

See original GitHub issue

Do 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

0reactions
github-actions[bot]commented, May 12, 2021

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Test Renderer - React
This package provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM...
Read more >
Fragments - React
<Columns /> would need to return multiple <td> elements in order for the rendered HTML to be valid. If a parent div was...
Read more >
Testing Recipes - React
Common testing patterns for React components. Note: This page assumes you're using Jest as a test runner. If you use a different test...
Read more >
Typechecking With PropTypes - React
To run typechecking on the props for a component, you can assign the special propTypes property: import PropTypes from 'prop-types'; class Greeting extends ......
Read more >
React.Component
These methods are called when there is an error during rendering, in a lifecycle method, or in the constructor of any child component....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found