我在gitlab测试管道中的所有测试中都有这个错误,但在本地所有测试都通过了。也许我遗漏了某个环境变量,或者与适配器有关({Enzyme.configure: new Adapter() })?
npm任务:
"test": "node scripts/test.js --env=jsdom"scripts/test.js:
'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控制台错误:
$ 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:
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()
})
})发布于 2017-11-06 22:48:52
我终于发现NODE_ENV没有被设置为“测试”或“开发”(而不是“生产”)。
https://stackoverflow.com/questions/47133729
复制相似问题