-
Notifications
You must be signed in to change notification settings - Fork 29
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
Fix wrong name printed in custom elements (when passed as props) #46
Conversation
It seems like the test is actually failing on travis. Why is the element thought to be "unknown"? |
The test passes on Node v6, but fails on Node v4/v5. I investigated a bit further and found that it's due to Node 6's inferred function names. Compare: // Node v6
> foo = function() {}
[Function: foo]
> foo.name
'foo'
>
// Node v4
> foo = function() {}
[Function]
> foo.name
''
> function foo() {}
undefined
> foo.name
'foo' I guess that the proposed change is in any case an improvement: it fixes the problem in v6, and it provides better behaviour in v4/v5: |
Ah I see, Node 6 isn't currently part of travis. Would you mind updating that? (remove node 5 and add node 6). I recommend changing the functional component to |
@@ -515,7 +515,7 @@ describe('prettyFormat()', () => { | |||
}); | |||
|
|||
it('supports a single element with custom React elements with props', () => { | |||
const Cat = () => React.createElement('div'); | |||
function Cat() { React.createElement('div') }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll need to write this as
function Cat() {
return React.createElement('div');
};
I was just writing that |
Hmm, @thejameskyle seems like the following would result in Unknown in jest
The problem seems to be multiple components definition in a single file. It feels more like an Istanbul / Jest issue. Any ideas? |
I managed to reproduce it even with a single component in a file: // ex.js
import React from 'react';
const A = () => React.createElement('span');
export default A; // __tests__/ex.test.js
import A from '../ex';
describe('A', () => {
it('renders correctly', () => {
console.log(`A's name: '${A.name}'`);
});
}); Running with |
When printing a custom element passed as a prop to another one with the
ReactElement
plugin, the name of the former is not printed correctly:The above test fails, since the following is generated:
This issue is related to jestjs/jest#2037.