小编Nik*_*hil的帖子

Next.JS & JEST - publicRuntimeConfig 未定义

使用 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)

unit-testing reactjs jestjs next.js

16
推荐指数
2
解决办法
1万
查看次数

next.js 为 NextJs 设置 ESLint

我已经使用“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

reactjs eslint next.js

14
推荐指数
2
解决办法
2万
查看次数

nextjs- typescript- 类型“IntrinsicAttributes 和 IntrinsicClassAttributes”上不存在属性“className”

我已经使用 typescript 链接创建了基本的 nextjs 应用程序 - https://github.com/zeit/next.js/tree/master/examples/with-typescript

我无法将 className 属性添加到任何元素。我收到以下错误。属性 'className' 不存在于类型 'IntrinsicAttributes & IntrinsicClassAttributes & Readonly & Readonly<{ children?: ReactNode; }>

我也收到其他属性的类型错误,例如链接元素上的 rel。

Head > 链接属性的错误

错误 2 类型检查错误

typescript reactjs next.js

5
推荐指数
1
解决办法
3352
查看次数

Android和IOS移动设备:计算浏览器屏幕高度,不包括地址栏和导航栏高度

我想在不考虑浏览器地址栏和底部导航栏高度的情况下计算浏览器高度。

的值screen.height将给出完整的浏览器高度。我在附加图像中以橙色突出显示区域。寻找适用于所有移动设备的通用解决方案

附上图片

html javascript css jquery

3
推荐指数
1
解决办法
1858
查看次数

标签 统计

next.js ×3

reactjs ×3

css ×1

eslint ×1

html ×1

javascript ×1

jestjs ×1

jquery ×1

typescript ×1

unit-testing ×1