Skip to content

Instantly share code, notes, and snippets.

@ivanbtrujillo
Created June 6, 2019 17:34
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/1ed8bca0bd9ccc53e6e29c1b2dbeeb62 to your computer and use it in GitHub Desktop.
Save ivanbtrujillo/1ed8bca0bd9ccc53e6e29c1b2dbeeb62 to your computer and use it in GitHub Desktop.
react-testing-library-article-7
import React, { useState } from "react";
const Sum = () => {
const [value1, setValue1] = useState();
const [value2, setValue2] = useState();
const [result, setResult] = useState();
const calculateSum = () => setResult(value1 + value2);
return (
<div>
<input
data-testid="value1"
value={value1}
onChange={e => setValue1(e.target.value)}
/>
<input
data-testid="value2"
value={value2}
onChange={e => setValue2(e.target.value)}
/>
<button data-testid="sum-button" onClick={calculateSum} />
<p data-testid="result-txt">{result}</p>
</div>
);
};
export default Sum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment