问题
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 import dotnetify = require("dotnetify");
, Jest passes test, but this is silly workaround. How to explain Jest, that dotnetify is not undefined?
Than you in advance.
回答1:
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:
import dotnetify = require("dotnetify")
来源:https://stackoverflow.com/questions/50427196/jest-typeerror-cannot-read-property-of-undefined