enzyme

Expected number of calls: >= 1 Received number of calls: 0

霸气de小男生 提交于 2021-01-07 02:40:54
问题 I am learning reactjs form with hooks, now I would like to test form on submit using jest and enzyme. here is my login component. import React from 'react' function Login() { const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const handleSubmit = async (e) => { e.preventDefault(); // ....api calLS } return ( <div> <form onSubmit={handleSubmit} className="login"> <input type="email" id="email-input" name="email" value={email} onChange={e => setEmail(e.target

Testing TextInput Component in react-native

a 夏天 提交于 2020-12-26 08:23:22
问题 I have some problems with testing TextInput changes in react-native with jest and enzyme . My component that handles user input basically looks like this (simplified): class Search extends React.PureComponent { onSearchTextChange = input => { // do something awesome }; render() { return ( <View> <TextInput onChangeText={debounce(this.onSearchTextChange, 800)} /> </View> ); } } I want to test the text input behaviour. This is what the test looks like right now: it('should render a text input

Testing TextInput Component in react-native

那年仲夏 提交于 2020-12-26 08:22:30
问题 I have some problems with testing TextInput changes in react-native with jest and enzyme . My component that handles user input basically looks like this (simplified): class Search extends React.PureComponent { onSearchTextChange = input => { // do something awesome }; render() { return ( <View> <TextInput onChangeText={debounce(this.onSearchTextChange, 800)} /> </View> ); } } I want to test the text input behaviour. This is what the test looks like right now: it('should render a text input

React 16 beta 版发布!

我的梦境 提交于 2020-12-24 16:00:44
作者: lizheming 编辑:魔卡 原文地址: http://www.zcfy.cc/@lizheming ━━━━━ 令人欣慰,React 16 首个 beta 版已经发布,可以公开测试了!🎉 下面我来告诉大家如何使用以及新版的一些值得注意的地方。 如何使用 安装 由于还是 beta 版,常规的 NPM 安装命令仍然会使用 15.6 正式版。beta 版我们使用 next 标签发布在 NPM 上,你需要使用如下命令安装使用 beta 版: # Yarn yarn add react@next react-dom@next # NPM npm install --save react@next react-dom@next Javascript 环境要求 由于 React 16 依赖 新的数据集合类型 Map 和 Set ,所以我们不支持一些老浏览器和设备(例如 <IE11)。如果你要支持它们的话,最好为项目引入一个全局的 Polyfill,core-js 和 babel-polyfill 都是不错的选择。 下面是在 React 16 中使用 core-js 来支持老浏览器的示例: import 'core-js/es6/map'; import 'core-js/es6/set'; import React from 'react'; import ReactDOM from

Testing react app with jest and enzyme token problem

谁都会走 提交于 2020-12-15 07:19:40
问题 I have a react app in which I have added unit testing, but one of my tests fails, Here is my test file, I want to test action creators getUser . When I run npm test I get the following error, FAIL UnitTests resources/js/tests/actions/index.test.js ● Test suite failed to run TypeError: Cannot read property 'getAttribute' of null 8 | 'Accept': 'application/json', 9 | 'Content-Type': 'application/json', > 10 | 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute(

Testing react app with jest and enzyme token problem

偶尔善良 提交于 2020-12-15 07:19:16
问题 I have a react app in which I have added unit testing, but one of my tests fails, Here is my test file, I want to test action creators getUser . When I run npm test I get the following error, FAIL UnitTests resources/js/tests/actions/index.test.js ● Test suite failed to run TypeError: Cannot read property 'getAttribute' of null 8 | 'Accept': 'application/json', 9 | 'Content-Type': 'application/json', > 10 | 'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute(

Jest not covered the function inside useEffect

瘦欲@ 提交于 2020-12-15 01:55:23
问题 I want to test a function that fetch something from server, it looks like this : import React, { useEffect } from 'react'; function Component1() { useEffect(() => { fetchSomeData(); }, []) const fetchSomeData = async () =>{ console.log('fetchSomeData') } return <div>Component1</div>; } export default Component1; and test file: import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { act } from 'react-dom/test-utils'; import Enzyme, { shallow } from

Jest not covered the function inside useEffect

五迷三道 提交于 2020-12-15 01:53:50
问题 I want to test a function that fetch something from server, it looks like this : import React, { useEffect } from 'react'; function Component1() { useEffect(() => { fetchSomeData(); }, []) const fetchSomeData = async () =>{ console.log('fetchSomeData') } return <div>Component1</div>; } export default Component1; and test file: import React from 'react'; import { render, unmountComponentAtNode } from 'react-dom'; import { act } from 'react-dom/test-utils'; import Enzyme, { shallow } from

Jest & Hooks : TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined

我是研究僧i 提交于 2020-12-13 10:36:53
问题 In create-react-app, I'm trying to simple test with jest but I'm getting this error : TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined. A part of my component AppBarUser.js /... const AppBarUser = () => { const classes = useStyles(); const [, formDispatch] = useContext(FormContext); const [t] = useContext(TranslationContext); const [openDrawer, setDrawer] = useState(false); const [userInfos, setData] = useState({}); useEffect(() => { const fetchData = async () => { try {

Jest & Hooks : TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined

谁说我不能喝 提交于 2020-12-13 10:36:45
问题 In create-react-app, I'm trying to simple test with jest but I'm getting this error : TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined. A part of my component AppBarUser.js /... const AppBarUser = () => { const classes = useStyles(); const [, formDispatch] = useContext(FormContext); const [t] = useContext(TranslationContext); const [openDrawer, setDrawer] = useState(false); const [userInfos, setData] = useState({}); useEffect(() => { const fetchData = async () => { try {