React native: Warning for Shallow renderer
我正在使用JEST框架进行单元测试。我正在使用酶中的Shallow进行DOM测试。运行jest命令后,我得到以下警告。
通过测试/CheckboxWithLabel-test.js
●控制台
console.error node_modules / fbjs / lib / warning.js:36
警告:浅渲染器已移至react-test-renderer / shallow。更新引用以消除此警告。
我的测试是
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import React from 'react'; import {shallow} from 'enzyme'; import CheckboxWithLabel from '../app/Component8/CheckboxWithLabel'; test('CheckboxWithLabel changes the text after click', () => { // Render a checkbox with label in the document const checkbox = shallow( <CheckboxWithLabel labelOn="On" labelOff="Off" /> ); expect(checkbox.text()).toEqual('Off'); checkbox.find('input').simulate('change'); expect(checkbox.text()).toEqual('On'); }); |
我的package.json
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | { "name":"myapp", "version":"0.0.1", "private": true, "scripts": { "start":"node node_modules/react-native/local-cli/cli.js start", "test":"jest" }, "dependencies": { "linkify-it":"^2.0.3", "prop-types":"^15.5.8", "react":"16.0.0-alpha.6", "react-dom":"^15.4.2", "react-native":"0.43.1" }, "devDependencies": { "babel-jest":"19.0.0", "babel-preset-es2015":"^6.24.0", "babel-preset-react-native":"1.9.1", "enzyme":"^2.8.2", "jest":"19.0.2", "react-addons-test-utils":"~15.1.0", "react-test-renderer":"16.0.0-alpha.6" }, "jest": { "preset":"react-native" } } |
来自酶文档:
如果您正在使用React> = 15.5,则除了酶之外,还必须确保还安装了以下npm模块(如果尚未安装):