Can not get display name in React when named export
See original GitHub issue🐛 Bug Report
To Reproduce
Steps to reproduce the behavior:
-
setup jest config with
ts-jest
-
create
App
component and named export it as bellow.
export const App = () => <div/>;
- create test file as bellow
test('<App/>', () => {
console.log(App.name);
});
- You can check
App.name
is undefined
Expected behavior
It should output App
when I executed console.log(App.name)
envinfo
System:
OS: Mac
Npm packages:
jest: ^26.2.2
ts-jest: ^26.1.4
typescript: ^3.9.7
babel(optional):
Issue Analytics
- State:
- Created 3 years ago
- Comments:10
Top Results From Across the Web
DisplayName of export function in React - Stack Overflow
I read React docs where it was told that by default ReactClass.displayName is defined and = name of class (function). I have two...
Read more >Context - React
Using context, we can avoid passing props through intermediate elements: ... Context object accepts a displayName string property. React DevTools uses this ...
Read more >What is export default in JavaScript ? - GeeksforGeeks
One is Named Exports and other is Default Exports. ... During the import, it is mandatory to use the same name of the...
Read more >Understanding the Difference Between Named and Default ...
Named and Default exports are not React-centric ideas. They are es6 features. However, this article will deal with the impacts they have in...
Read more >Function.prototype.displayName - JavaScript - MDN Web Docs
The displayName property is not initially present on any function — it's added by ... React devtools also use the displayName property when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah ha nice 👍 I was also surprised that each browser has their own way of producing
name
so when I tested out some codes, chrome gave me different results than jest.you can also write your own TypeScript AST transformer and give it to
ts-jest
😃, following that babel plugin does