gpt4 book ai didi

javascript - JEST 测试,从 enzyme 导入配置时出错

转载 作者:行者123 更新时间:2023-11-28 20:35:27 26 4
gpt4 key购买 nike

我正在尝试在此处的 repo 中运行我的测试:https://github.com/Futuratum/moon.holdings

但是我收到以下错误

/Users/leongaban/projects/Futuratum/moon.holdings/jest.config.js:1 (function (exports, require, module, __filename, __dirname) { import { configure } from 'enzyme'

我的测试过去一直有效,我没有做任何更改,很好奇是什么导致了这个问题?

我的 jest.config.js 文件看起来是正确的:

import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'

configure({ adapter: new Adapter() })

package.json

{
"name": "moon.holdings",
"version": "2.0.0",
"description": "Moon Holdings: track your cryptocurrency portfolio.",
"main": "index.js",
"scripts": {
"dev": "next -p 7777",
"build": "next build",
"start": "next -p 7777",
"test": "NODE_ENV=test jest --watch --no-cache",
"test-win": "SET NODE_ENV=test&& jest --watch"
},
"author": "Futuratum",
"license": "UNLICENSED",
"dependencies": {
"@zeit/next-sass": "^1.0.1",
"@zeit/next-typescript": "^1.1.1",
"axios": "^0.18.0",
"decko": "^1.2.0",
"next": "^8.0.4-canary.10",
"next-routes": "^1.4.2",
"node-sass": "^4.11.0",
"ramda": "^0.26.1",
"ramda-adjunct": "^2.17.0",
"react": "^16.7.0",
"react-adopt": "^0.6.0",
"react-dom": "^16.7.0",
"react-ga": "^2.5.7",
"react-redux": "^6.0.0",
"react-transition-group": "^2.5.0",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"styled-components": "4.0.3",
"tslint": "^5.12.1",
"tslint-react": "^3.6.0",
"typescript": "^3.2.4",
"waait": "^1.0.2"
},
"devDependencies": {
"@babel/plugin-proposal-decorators": "^7.3.0",
"@babel/preset-typescript": "^7.1.0",
"@types/enzyme": "^3.1.15",
"@types/jest": "^23.3.13",
"@types/next": "^7.0.6",
"@types/ramda": "^0.25.49",
"@types/react": "^16.7.20",
"@types/react-dom": "^16.0.11",
"@types/react-redux": "^7.0.1",
"@types/styled-components": "4.0.3",
"@types/zeit__next-typescript": "^0.1.1",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^24.1.0",
"babel-plugin-sass-vars": "^0.2.1",
"babel-plugin-styled-components": "^1.10.0",
"enzyme": "^3.6.0",
"enzyme-adapter-react-16": "^1.5.0",
"enzyme-to-json": "^3.3.4",
"jest": "^24.1.0"
},
"jest": {
"setupTestFrameworkScriptFile": "<rootDir>/jest.setup.js",
"testPathIgnorePatterns": [
"<rootDir>/.next/",
"<rootDir>/node_modules/"
],
"transform": {
".*": "babel-jest",
"^.+\\.js?$": "babel-jest",
"^.+\\.ts?$": "babel-jest",
"^.+\\.tsx?$": "babel-jest"
},
"moduleFileExtensions": [
"js",
"json",
"ts",
"tsx"
],
"modulePaths": [
"<rootDir>/components/",
"<rootDir>/pages/",
"<rootDir>/shared/"
]
}
}

enter image description here

最佳答案

看起来你在 this commit 中不小心将 jest.setup.js 重命名为 jest.config.js .

将它改回 jest.setup.js,它应该可以工作。


详情

jest.config.js 是一个特殊文件,用于设置Jest configuration options .

enzyme 配置通常在 setupTestFrameworkScriptFile 文件中完成,用于旧版本的 JestsetupFilesAfterEnv对于更新版本的 Jest

您的 package.json 已将 setupTestFrameworkScriptFile 设置为 jest.setup.js

根据该信息,我怀疑 jest.setup.js 可能被意外重命名,并且能够在 repo 历史记录中找到它发生的提交。

关于javascript - JEST 测试,从 enzyme 导入配置时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55893161/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com