Skip to content

Instantly share code, notes, and snippets.

@Clarity-89
Clarity-89 / testing_base.tsx
Last active August 13, 2020 11:14
Enzyme vs React testing Library form testing comparison
import React from 'react';
import { NavModel } from '@grafana/data';
import { updateLocation } from 'app/core/actions';
import { mockToolkitActionCreator } from '../../../test/core/redux/mocks';
import { Props, ReportsSettingsPage } from './ReportsSettingsPage';
beforeEach(() => {
jest.clearAllMocks();
});
import React from "react";
import styled from "@emotion/styled";
import { useForm } from "react-hook-form";
export const Recipe = () => {
return (
<Container>
<h1>New recipe</Title>
</Container>
);
// FieldSet.js
export const FieldSet = ({ label, children }) => {
return (
<Container>
{label && <Legend>{label}</Legend>}
<Wrapper>{children}</Wrapper>
</Container>
);
};
import React from "react";
import styled from "@emotion/styled";
import { Button, Form } from "semantic-ui-react";
import { FieldSet } from "./FieldSet";
const fieldWidth = 8;
export const Recipe = () => {
return (
<Container>
import React from "react";
import styled from "@emotion/styled";
import { Button, Form } from "semantic-ui-react";
import { FieldSet } from "./FieldSet";
import { useForm } from "react-hook-form";
const fieldWidth = 8;
export const Recipe = () => {
const { register, handleSubmit } = useForm();
<input type="text" name="name" id="name" ref={register({required: true})} /> 
ref={register({required: 'This field is required'})}
export const Recipe = () => {
const { register, handleSubmit, errors } = useForm();
const submitForm = formData => {
console.log(formData);
};
return (
<Container>
<h1>New recipe</h1>