首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >react-test-renderer浅渲染器在生产模式下不可用

react-test-renderer浅渲染器在生产模式下不可用
EN

Stack Overflow用户
提问于 2017-11-06 17:33:53
回答 1查看 414关注 0票数 0

我在gitlab测试管道中的所有测试中都有这个错误,但在本地所有测试都通过了。也许我遗漏了某个环境变量,或者与适配器有关({Enzyme.configure: new Adapter() })?

npm任务:

代码语言:javascript
复制
"test": "node scripts/test.js --env=jsdom"

scripts/test.js:

代码语言:javascript
复制
'use strict'

const jest = require('jest')

// Makes the script crash on unhandled rejections instead of silently
// ignoring them. In the future, promise rejections that are not handled will
// terminate the Node.js process with a non-zero exit code.
process.on('unhandledRejection', (err) => {
  throw err
})

const argv = process.argv.slice(2)

// Watch unless on CI or in coverage mode
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
  argv.push('--watch')
}

jest.run(argv)

Gitlab控制台错误:

代码语言:javascript
复制
$ node scripts/test.js --env=jsdom
FAIL src/components/ui/Grid/__tests__/Grid.spec.jsx
  ● Test suite failed to run

    shallow renderer is not available in production mode.
        at Error (native)

      at Object.<anonymous> (node_modules/react-test-renderer/shallow.js:4:9)
      at Object.<anonymous> (node_modules/enzyme-adapter-react-16/build/ReactSixteenAdapter.js:21:16)
      at Object.<anonymous> (node_modules/enzyme-adapter-react-16/build/index.js:2:18)
      at Object.<anonymous> (src/components/ui/Grid/__tests__/Grid.spec.jsx:3:27)

Grid.spec.jsx:

代码语言:javascript
复制
import React from 'react'
import Enzyme, { shallow } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16'
import Grid from '../index'

const { Row, Column } = Grid
Enzyme.configure({ adapter: new Adapter() })

describe('Grid', () => {
  it('should have a Row and a Column', () => {
    expect(Grid.Row).toBeDefined()
    expect(Grid.Column).toBeDefined()
  })
})
EN

回答 1

Stack Overflow用户

发布于 2017-11-06 22:48:52

我终于发现NODE_ENV没有被设置为“测试”或“开发”(而不是“生产”)。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47133729

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档