Cannot Import TypeScript Module In Test File
See original GitHub issueLink to bug demonstration repository.
https://github.com/dawsonc623/nyc-bug-demo
Expected Behavior
Running yarn test should yield passing tests with 100% coverage.
Observed Behavior
Running yarn test fails with the following errors and reports 0% Statement and Line coverage (Branch and Funcs are at 100% presumably because there are none in the file).
TSError: ⨯ Unable to compile TypeScript:
src/app/foo.ts(1,212): error TS2351: Cannot use 'new' with an expression whose type lacks a call or construct signature.
src/app/foo.ts(1,656): error TS2339: Property 'hash' does not exist on type '{ path: string; statementMap: { "0": { start: { line: number; column: number; }; end: { line: number; column: number; }; }; }; fnMap: {}; branchMap: {}; s: { "0": number; }; f: {}; b: {}; _coverageSchema: string; }'.
There is also a massive stack trace, but it does not seem particularly useful to post the whole thing here.
Forensic Information
Operating System: Ubuntu 18.04.2 LTS on Windows 10 via the Windows Subsystem for Linux Environment Information: https://gist.github.com/dawsonc623/5d175ea45c6c5fb5359dc11bfeb05df3
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Jest cannot import TypeScript file - javascript
Test suite failed to run Jest encountered an unexpected token This usually means that you are trying to import a file which Jest...
Read more >TypeScript Jest: Cannot use import statement outside module
The TypeScript jest error "Cannot use import statement outside module" occurs when we misconfigure jest in a TypeScript project and run test files...
Read more >Cannot use import statement outside a module [React ...
When building a web application, you may encounter the SyntaxError: Cannot use import statement outside a module error.
Read more >TypeScript: Documentation - Modules
In TypeScript, just as in ECMAScript 2015, any file containing a top-level import or export is considered a module. Conversely, a file without...
Read more >Configuring Jest
To read TypeScript configuration files Jest requires ts-node . ... This option tells Jest that all imported modules in your tests should be ......
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 Free
Top 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

use ts-node/register/transpile-only instead from docs https://istanbul.js.org/docs/tutorials/typescript/
@coreyfarrell Fantastic news! Thanks for tackling this.