App.tsx is of wrong type only when testing
See original GitHub issueI have a small React Native (Expo) app written in TypeScript and have just began to write some tests for it. I started to write tests for some very simple components, and it seems to work out just fine.
However, when I try to write tests for my App.tsx I get the following error:
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object
I have:
- made sure it’s a correctly written functional component
- tripple checked the import - which is correct
- tried to import it in another file and checked type there - which results in
function
. - stripped out everything from my App.tsx and made it just a valid component in it’s simplest form.
However, when I import it into my App.test.tsx to test it it’s imported as an object.
What am I missing here? 😃
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
TypeScript errors doesn't show when running tests through ...
TypeScript errors doesn't show when running tests through JEST with create-react-app. Save this question. Show activity on this post.
Read more >Error Boundaries - React
Only class components can be error boundaries. In practice, most of the time you'll want to declare an error boundary component once and...
Read more >TypeError: "x" is not a function - JavaScript - MDN Web Docs
The JavaScript exception "is not a function" occurs when there was an attempt to call a value from a function, but the value...
Read more >TSConfig Reference - Docs on every TSConfig option
error : This preserves all imports (the same as the preserve option), but will error when a value import is only used as...
Read more >Tutorial: Create a Node.js and React app in Visual Studio
Some of the information in this article applies only to the Node.js project type (.njsproj). Before you begin, here's a quick FAQ to ......
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
I know this is closed but I believe (I did clone your repro and this plus adding
preset: "react-native"
for a separate issue, successfully ran the tests) the fix rather than just renaming would be to add to your jest config:Apparently theres an issue with the defaults set that the json appears before ts/tsx and that causes the issue. Hope it helps someone 😃
@KieranO547 wow, you save my day 👍