我正在尝试使用 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 …Run Code Online (Sandbox Code Playgroud)