我正在尝试在NextJS应用程序中设置Jest,目前在jest.config.js
文件中:
module.exports = {
testPathIgnorePatterns: ["<rootDir>/.next/", "node_modules/"],
setupFilesAfterEnv: ["<rootDir>/__tests__/setupTests.tsx"],
transform: {
"^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
}
};
在我的setupTests.tsx
文件中,我有:
import "@testing-library/jest-dom/extend-expect";
然而当我运行npm run test
时,我得到了以下错误:
Module identity-obj-proxy in the transform option was not found.
<rootDir> is: ....
如果我删除
jest.config.js
中的这一行,会得到以下结果:Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".
globals.css:2
body {
^
SyntaxError: Unexpected token '{'
> 5 | import "../styles/globals.css";
我应该如何配置 css
和 scss
文件?
** 编辑 **
我确保在我的 devDependencies 中有 identity-obj-proxy
,但现在出现错误:
Test suite failed to run
Test suite failed to run
TypeError: Jest: a transform must export a `process` function.
> 5 | import "../styles/globals.css";
| ^
6 | import React from "react";