ts-jest fails to run a tsx test file because of "Import" from a module's js file
The problem is that Jest is not transforming that file. And in plain JS, import
is not valid. You need to configure Jest so it will transform that file.
First, change the transform
to also process files with extensions js
or jsx
(in addition to ts
files:)
"jest": { "transform": { "^.+\\.(ts|js)x?$": "ts-jest" },
Next you need to whitelist the directory, so Jest does transform it. This skips transforming all files in node_modules
except the quill-mention
dir.
"transformIgnorePatterns": [ "<rootDir>/node_modules/(?!(quill-mention)/)" ]
This should get past the problems with quill-mention
. And it should now fail with ReferenceError: MutationObserver is not defined
, which is a different issue, having to do with Jest's JSDom environment it uses. You can read about how to fix that here:
Testing MutationObserver with Jest
You may also want to consider moving to babel-jest
+ @babel/preset-typescript
instead of using ts-jest
.