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

TypeError: Function.prototype.name sham getter called on non-function #1889

Closed
3 of 13 tasks
Ridermansb opened this issue Nov 6, 2018 · 5 comments
Closed
3 of 13 tasks

Comments

@Ridermansb
Copy link

Current behavior

When run with --coverage i get this error..

TypeError: Function.prototype.name sham getter called on non-function

● <ErrorBoundary> component › should render with message if error occour

TypeError: Function.prototype.name sham getter called on non-function

  20 | 		);
  21 |
> 22 | 		expect(wrapper).toMatchSnapshot();
     | 		                ^
  23 | 	});
  24 |
  25 | 	it("should render if error occour", function() {

  at Function.getName (../node_modules/function.prototype.name/implementation.js:31:9)
  at displayNameOfNode (../node_modules/enzyme-adapter-utils/build/Utils.js:156:95)
  at ReactSixteenAdapter.displayNameOfNode (../node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:605:62)
  at typeName (../node_modules/enzyme/build/Debug.js:60:43)
  at internalNodeToJson (../node_modules/enzyme-to-json/mount.js:70:31)
  at mountToJson (../node_modules/enzyme-to-json/mount.js:93:12)
  at Object.<anonymous>.exports.default (../node_modules/enzyme-to-json/index.js:14:32)
  at Object.print (../node_modules/enzyme-to-json/createSerializer.js:22:40)
  at printPlugin (../node_modules/pretty-format/build/index.js:287:16)
  at prettyFormat (../node_modules/pretty-format/build/index.js:485:16)
  at Object.throwingMatcher (../node_modules/expect/build/index.js:320:33)
  at Object.toMatchSnapshot (src/components/molecules/ErrorBoundary/ErrorBoundary.test.jsx:22:19)

`

If I not run with coverage, everything works fine

Question posted on Stackoverflow

Expected behavior

Run tests with coverage without error

Your environment

  • macOS Mojave 10.14.1 .
  • node 10.11.0
  • npm 6.4.1
  • yarn 1.10.1
  • zsh
  • lerna 2.11.0

API

  • shallow
  • mount
  • render

Version

library version
enzyme 3.7.0
react 16.4.1
react-dom 16.4.1
react-test-renderer
adapter (below)

Adapter

  • enzyme-adapter-react-16
  • enzyme-adapter-react-16.3
  • enzyme-adapter-react-16.2
  • enzyme-adapter-react-16.1
  • enzyme-adapter-react-15
  • enzyme-adapter-react-15.4
  • enzyme-adapter-react-14
  • enzyme-adapter-react-13
  • enzyme-adapter-react-helper
  • others ( )
@ljharb
Copy link
Member

ljharb commented Nov 6, 2018

What’s your test code look like?

@ljharb
Copy link
Member

ljharb commented Nov 6, 2018

Based on your SO post, you should indeed be explicitly naming your class, but also, this is because your error fallback is a string - and enzyme does not yet support rendering non-elements (see #1149).

For now, you can make your error fallback be a React fragment.

@adamboduch
Copy link

Why does this only happen with --coverage?

@ljharb
Copy link
Member

ljharb commented Dec 11, 2018

It's possible that jest's --coverage code rewriting is introducing a bug.

@ljharb
Copy link
Member

ljharb commented May 4, 2019

The linked SO post is self-answered as resolved; I'm also unable to reproduce this.

I believe it's a bug in enzyme-to-json around anonymous components - I'm closing this until it can be reproduced.

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

No branches or pull requests

3 participants