使用 next.js 和 Jest 运行单元测试用例时出现“publicRuntimeConfig undefined”错误
我正在使用下一个 9.1.1。我尝试了以下解决方案,但它不起作用。
我也在 jest.setup.js 中设置了配置。请参阅下面的代码
import { setConfig } from 'next/config';
import config from './next.config';
setConfig(config.publicRuntimeConfig);
Run Code Online (Sandbox Code Playgroud)我尝试在测试用例文件中使用笑话模拟。
jest.mock('next/config', () => () => ({
publicRuntimeConfig: {
key: 'abc
}
}));
Run Code Online (Sandbox Code Playgroud)我已经使用“npx create-next-app”和 .eslintrc.json 文件创建了基本的 next.js 应用程序以添加 eslint 规则。但它不起作用。如何将 linting 规则添加到 nextjs 配置
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"standard"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly",
"React": "writable"
},
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": 2018,
"sourceType": "module"
},
"plugins": [
"react"
],
"rules": {
"react/react-in-jsx-scope": "off"
}
}
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这个解决方案 - https://medium.com/@joelmasters/setting-up-eslint-for-nextjs-37163d4cabaa
我已经使用 typescript 链接创建了基本的 nextjs 应用程序 - https://github.com/zeit/next.js/tree/master/examples/with-typescript
我无法将 className 属性添加到任何元素。我收到以下错误。属性 'className' 不存在于类型 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; }>
我也收到其他属性的类型错误,例如链接元素上的 rel。
next.js ×3
reactjs ×3
css ×1
eslint ×1
html ×1
javascript ×1
jestjs ×1
jquery ×1
typescript ×1
unit-testing ×1