sid*_*udi 7 javascript destructuring reactjs jestjs enzyme
我正在尝试使用 Jest 对我的 React 应用程序中的一个功能组件进行 SnapShot 验证。这是使用 Jest 的组件和测试文件
import React, { useState } from 'react';
import useForm from 'react-hook-form';
import { useAppState } from 'Shared/store';
...
const Form = () => {
const {customReducer, dispatch} = useAppState();
const { register, handleSubmit, errors, reset } = useForm({});
//custom form methods
return (
<>
<Form ...>
...
</Form>
....
</>
);
export default Form;
Run Code Online (Sandbox Code Playgroud)
和我使用 Jest 的测试
import React from 'react';
import TestRenderer from 'react-test-renderer';
import ShallowRenderer from 'react-test-renderer/shallow';
import Form from '../form';
describe('<Form />', () => {
test('Snapshot', () => {
const tree = TestRenderer.create(<Form />).toJSON();
expect(tree).toMatchSnapshot();
});
});
Run Code Online (Sandbox Code Playgroud)
并且我遇到了错误 TypeError: Invalid trial to destructure non-iterable instance
也试过酶,但得到同样的错误。花时间参考其他相关问题,但无法弄清楚。谢谢你。
| 归档时间: |
|
| 查看次数: |
5339 次 |
| 最近记录: |