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
Stateless component loses name when generating coverage #1824
Comments
Can you try updating to Node 6.5 and see if this still happens? It does some things differently in how it infers function names. |
Just updated to the latest via Homebrew:
but I'm getting the same result. |
yeah this kind of sucks. Istanbul wraps functions with other anonymous functions and we take the function name that node gives to the rendered component :( |
You can also add |
Yup const Foo = () => <div>Foo</div>
Foo.displayName = "Foo" So is the issue with Istanbul or is there something Jest/React can do? The interesting thing is that the way I had Mocha/Istanbul set up didn't seem to run into this problem. It only happened when I tried to use Jest to run the same tests. Other than that the migration was very painless and Jest "just worked". |
Passing the component to describe("<Foo>", () => {
it("renders 'Foo'", () => {
const wrapper = mount(<Foo/>)
console.log(wrapper.debug())
return expect(wrapper.find(Foo).text()).to.be.equal("Foo")
})
}) Maybe this is actually the correct way to use Enzyme and it just happened to usually work with strings. |
@cpojer is there a potential solution for this in Instanbul, or is just setting |
* Improve accuracy of code coverage with latest jest. Fixes #293 * Use constructor selector because Istanbul instrumentation wraps with anonymous functions. See jestjs/jest#1824
I don't fully understand why this issue is closed - I am still running into it. The suggestion to pass the component instead of a string to |
Same here |
Try:
See https://github.com/airbnb/enzyme/blob/master/packages/enzyme/src/Debug.js#L11-L15 |
@stief510 I was able to make it work with a babel plugin: https://www.npmjs.com/package/babel-plugin-transform-react-stateless-component-name |
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. |
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
First, I'm not sure if this is a problem with Jest or with Enzyme, but I first noticed this when migrating another project from Mocha to Jest.
When mounting a stateless function component with Enzyme, the component name is
preserved when running
jest
, but not when runningjest --coverage
. This iscausing unit tests to fail when generating coverage that otherwise succeed.
For example, when mounting the component
results in
but when generating coverage, it results in
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal repository on GitHub that we can
npm install
andnpm test
.Attempt at minimal repository
What is the expected behavior?
Testing with
--coverage
succeeds.Run Jest again with
--debug
and provide the full configuration it prints. Please mention your node and npm version and operating system.node v6.4.0
npm v3.10.3
OS X 10.11.6
debug output
The text was updated successfully, but these errors were encountered: