Skip to content
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

render does not work with jest coverage report. #622

Closed
vishnu4 opened this issue Mar 25, 2020 · 10 comments
Closed

render does not work with jest coverage report. #622

vishnu4 opened this issue Mar 25, 2020 · 10 comments

Comments

@vishnu4
Copy link

vishnu4 commented Mar 25, 2020

  • @testing-library/react version:
    10.0.1
  • react version:
    16.13.1
  • node version:
    12.14.0
  • npm (or yarn) version:
    6.13.4

Relevant code or config:

import { render } from "@testing-library/react";
import React from "react";
import { ThemeProvider } from "emotion-theming";

const renderWithTheme = (ui: React.ReactChild, options = {}) => {
  const theme = {
    colors: {
      white: "#f7f7f7",
      borderColor: "#dde2e7",
      lightGray: "#9f9d9d",
      darkGray: "#343A40",
      black: "#2d2d2d",
      fontColor: "#212529",
      logoBlack: "#1d2122",
      accentColor: "#d83326",
    },
  };

  return render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>, options);
};

export default renderWithTheme;

What you did:

running

npm run jest

vs

npm run jest --coverage

What happened:

running jest by itself works fine, no issues. running jest with coverage gives me this error:

Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.

  17 |   };
  18 |
> 19 |   return render(<ThemeProvider theme={theme}>{ui}</ThemeProvider>, options);
     |          ^
  20 | };
  21 |
  22 | export default renderWithTheme;

Reproduction:

Problem description:

Suggested solution:

i see this similar issue here jestjs/jest#6827 , but honestly i don't know if the issue lies with jest or with react-testing-library. downgrading jest from 25.1.0 to 24.9.0 does not seem to help though.

@alexkrolick
Copy link
Collaborator

sounds like an issue with how the --coverage flag instrumentation interacts with babel

@omBratteng
Copy link

I had the same issue. Delete my lockfile, and installed packages again. Removed my problem

@vishnu4
Copy link
Author

vishnu4 commented Mar 26, 2020

@omBratteng unfortunately that didn't fix it for me. Thanks though.

@rovervannispen
Copy link

I have the same issues, even after deleting my lock file.

@prometium
Copy link

After the latest jest and babel updates (don't know what exactly) had the same issue.

I solved this by adding moduleFileExtensions: ['js'] to jest.config.js.

It looks weird, but maybe will help someone too.

@vishnu4
Copy link
Author

vishnu4 commented Mar 28, 2020

@prometium that didn't fix it for me either unfortunately. my jest.config.js already has
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],

@vishnu4
Copy link
Author

vishnu4 commented Apr 1, 2020

so i still don't know what caused this to suddenly break for me, but changing the coverage provider and adding to my jest.config:

coverageProvider: "v8", 
testEnvironment: "jest-environment-jsdom-sixteen",

fixed the issue for me. I don't think this has anything to do with react-testing-library, so closing.

@vishnu4 vishnu4 closed this as completed Apr 1, 2020
@dkleber89
Copy link

Same Issue here ... Is there any way to solve this Problem when CRA is not ejected?

svdo added a commit to Zwaai-app/infections-server that referenced this issue Apr 17, 2020
When running tsx tests I get "Nothing was returned from render".
testing-library/react-testing-library#622
@LucasAndrad
Copy link

@vishnu4 thanks, finally something that worked for me, I have already tried many solutions.

@dkleber89 I saw some people downgraded the react-scripts version (link here)

svdo pushed a commit to Zwaai-app/infections-server that referenced this issue Jul 1, 2020
When running tsx tests I get "Nothing was returned from render".
testing-library/react-testing-library#622
@aruniverse
Copy link

Do we know what the underlying issue here is? What changed in between CRA 3.4.0 & 3.4.1 that caused this to happen? Do we know if this issue will be resolved for the next CRA release?

facebook/create-react-app@v3.4.0...v3.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants