Last active
December 15, 2020 09:35
-
-
Save ovpv/a9b827be8f2b17693180e626983f7c4b to your computer and use it in GitHub Desktop.
Jest Mock: App file where moment js is used
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from "react"; | |
import "./styles.css"; | |
import moment from "moment"; | |
export default function App() { | |
const [date, setDate] = useState(""); | |
const [age, setAge] = useState(0); | |
const calculateAge = () => { | |
console.log('diff called'); | |
const calcAge = moment().diff(date, "years"); | |
setAge(calcAge); | |
}; | |
return ( | |
<div className="App"> | |
<h2>How old are you?</h2> | |
<label>Birthday: </label> | |
<input | |
type="date" | |
onChange={(e) => setDate(e.target.value)} | |
value={date} | |
id="birthday" | |
name="birthday" | |
/> | |
<button disabled={!date.length} onClick={calculateAge}> | |
Calculate Age | |
</button> | |
<div>Your age is: {age}</div> | |
</div> | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment