react-test-renderer

ReactTestUtils has been moved

 ̄綄美尐妖づ 提交于 2019-12-03 18:57:55
问题 I'm starting learning React and while I was doing some tests i noticed two warning messages: Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning. Warning: Shallow renderer has been moved to react-test-renderer/shallow. Update references to remove this warning. They don't prevent the tests from running nor from properly validating, but there is always this error. By looking at the docs, I found this page, even after I included those lines

How to test a react component that is dependent on useContext hook?

感情迁移 提交于 2019-12-03 06:51:34
问题 I have a component that uses useContext and then its output is dependent on the value in the context. A simple example: import React, { useContext } from 'react'; const MyComponent = () => { const name = useContext(NameContext); return <div>{name}</div>; }; When testing this component with the shallow renderer from react and jest snapshots. How can I change the value of NameContext ? 回答1: In general, using hooks shouldn't change testing strategy much. The bigger issue here actually isn't the

How to mock a third party react-native component with jest?

邮差的信 提交于 2019-12-01 13:05:36
I am using the NumericInput and it works fine when I run the application on my device. However, when I run jest , I get all kind of errors: TypeError: Cannot read property 'default' of undefined at new Icon (node_modules/react-native-vector-icons/lib/create-icon-set.js:42:389) at constructClassInstance (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:3435:18) at updateClassComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6606:5) at beginWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7563:16) at

How to mock a third party react-native component with jest?

半城伤御伤魂 提交于 2019-12-01 10:33:55
问题 I am using the NumericInput and it works fine when I run the application on my device. However, when I run jest , I get all kind of errors: TypeError: Cannot read property 'default' of undefined at new Icon (node_modules/react-native-vector-icons/lib/create-icon-set.js:42:389) at constructClassInstance (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:3435:18) at updateClassComponent (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6606:5) at

ReactTestUtils has been moved

久未见 提交于 2019-11-30 03:11:41
I'm starting learning React and while I was doing some tests i noticed two warning messages: Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning. Warning: Shallow renderer has been moved to react-test-renderer/shallow. Update references to remove this warning. They don't prevent the tests from running nor from properly validating, but there is always this error. By looking at the docs, I found this page , even after I included those lines they recommend, the warning message is still showing up. I'm trying a very simple test to start with,