作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在测试使用 jest 构建一个带有汇总的包,每当我使用 async/await 时都会抛出错误。我不知道出了什么问题。我尝试了不同的灵魂,但它不起作用。
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
at loadCjsDefault (node_modules/@babel/core/lib/config/files/module-types.js:77:18)
at loadCjsOrMjsDefault (node_modules/@babel/core/lib/config/files/module-types.js:49:16)
at loadCjsOrMjsDefault.next (<anonymous>)
at readConfigJS (node_modules/@babel/core/lib/config/files/configuration.js:190:47)
at readConfigJS.next (<anonymous>)
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down.
at _parser (node_modules/@babel/core/lib/parser/index.js:9:16)
at parser (node_modules/@babel/core/lib/parser/index.js:54:18)
at parser.next (<anonymous>)
at normalizeFile (node_modules/@babel/core/lib/transformation/normalize-file.js:93:38)
at normalizeFile.next (<anonymous>)
● Cannot log after tests are done. Did you forget to wait for something async in your test?
Attempted to log "TypeError: (0 , _parser(...).parse) is not a function
at parser (D:\projects\js\published\builderz\node_modules\@babel\core\lib\parser\index.js:54:34)
at parser.next (<anonymous>)
at normalizeFile (D:\projects\js\published\builderz\node_modules\@babel\core\lib\transformation\normalize-file.js:93:38)
at normalizeFile.next (<anonymous>)
at run (D:\projects\js\published\builderz\node_modules\@babel\core\lib\transformation\index.js:31:50)
at run.next (<anonymous>)
at Object.transform (D:\projects\js\published\builderz\node_modules\@babel\core\lib\transform.js:27:41)
at transform.next (<anonymous>)
at evaluateSync (D:\projects\js\published\builderz\node_modules\gensync\index.js:244:28)
at Object.sync (D:\projects\js\published\builderz\node_modules\gensync\index.js:84:14) {
code: 'PLUGIN_ERROR',
plugin: 'babel',
hook: 'transform',
id: 'D:\\projects\\js\\published\\builderz\\test\\samples\\pure\\src\\index.js',
watchFiles: [
'D:\\projects\\js\\published\\builderz\\test\\samples\\pure\\src\\index.js'
]
}".
import { resolve } from "path";
import builderz from "../src";
jest.useFakeTimers();
describe("production", () => {
it("test pure js", async () => {
await builderz({
isSilent: true,
paths: [resolve(__dirname, "./samples/pure")]
});
// update it later of cource:
expect(true).toEqual(true);
});
});
module.exports = api => {
api.cache(true);
return {
presets: [
[
"@babel/preset-env",
{
targets: {
node: "current"
}
}
]
]
};
};
最佳答案
添加 "testEnvironment": "jsdom"
进入 jest
package.json 中的键
"jest": {
"testEnvironment": "jsdom",
"preset": "react-native",
...
关于javascript - 引用错误 : You are trying to `import` a file after the Jest environment has been torn down: at loadCjsDefault,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60781238/
我是一名优秀的程序员,十分优秀!