Im trying to test my React class, that has import dotnetify from "dotnetify";
import. That works fine, but Jest says, that dotnetify is undefined. If i change to const dotnetify = require("dotnetify");
, Jest passes test, but this is silly workaround. How to explain Jest, that dotnetify is not undefined?
Than you in advance.
That works fine, but Jest says, that dotnetify is undefined. If i change to const dotnetify = require ("dotnetify");, Jest passes test, but this is silly workaround.
This cannot be 'explained' to Jest, it's really undefined. There are several ways to handle CommonJS modules in TypeScript. As explained in this answer, there will be default import in CommonJS packge only if synthetic imports were enabled with esModuleInterop ( allowSyntheticDefaultImports) compiler option.
we were using jest from unit testing in react-native. It was working well. We just deleted npm and installed it again and then when we tried to run unit test (npm test) we are getting following error and we are not able to run test cases.
Maybe jest should not depend on jest-cli, so that users are forced to add an explicit dependency to their project (at the correct version) if they want to use it? Including the appropriate peerDependencies should at least provide a warning of this kind of problem.
This cannot be 'explained' to Jest, it's really undefined.
There are several ways to handle CommonJS modules in TypeScript. As explained in this answer, there will be default import in CommonJS packge only if synthetic imports were enabled with esModuleInterop
(allowSyntheticDefaultImports
) compiler option.
Otherwise it should be done like:
import * as dotnetify from "dotnetify";
Or with TypeScript-specific syntax:
import dotnetify = require("dotnetify")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With