question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

App.tsx is of wrong type only when testing

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

7reactions
kieran-osgoodcommented, Jul 12, 2020

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:

"moduleFileExtensions": 
[
	"ts",
	"tsx",
	"js",
	"jsx",
	"json",
	"node"
]

Apparently theres an issue with the defaults set that the json appears before ts/tsx and that causes the issue. Hope it helps someone 😃

1reaction
AngelTrinidadcommented, Oct 26, 2020

@KieranO547 wow, you save my day 👍

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found