Skip to content

Instantly share code, notes, and snippets.

@ivanbtrujillo
Created June 6, 2019 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanbtrujillo/aecdf9cd9dab29171b6d1dabebe55377 to your computer and use it in GitHub Desktop.
Save ivanbtrujillo/aecdf9cd9dab29171b6d1dabebe55377 to your computer and use it in GitHub Desktop.
react-testing-library-article-6
import React from "react";
import { render, cleanup, fireEvent } from "@testing-library/react";
import Sum from "./Sum";
import "jest-dom/extend-expect";
describe("Sum", () => {
it('should sum value1 and value2 and show the result', () => {
const { getByTestId } = render(<Sum />);
const firstInput= getByTestId("value1");
fireEvent.change(firstInput, { target: { value: 1 } } );
const secondInput= getByTestId("value2");
fireEvent.change(secondInput, { target: { value: 1 } } );
const sumBtn = getByTestId("sum-button");
fireEvent.click(sumBtn);
const result = getByTestId("result-txt");
expect(result).toHaveTextContent(2);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment