I'm totally new to this writing test cases in react.I want to write a test case for the below code.I should check if it outputs the correct greeting as Good Morning,Good Afternoon,Good Evening when different time is given.
Greet.js
import { useState,useEffect } from 'react';
import './App.css';
function Greet(props) {
const [greet, setGreeet] = useState("");
useEffect(() => {
var today = new Date();
var time = today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds();
var t1="00:00:00";
var t2="12:00:00";
var t3="17:00:00";
var t4="23:60:60"
if(t1<=time && time<=t2){
setGreeet("Morning")
}
else if(t2<time && time<=t3){
setGreeet("Afternoon")
}
else if(t3<time && time<=t4){
setGreeet("Evening")
}
}, []);
return (
<div className="App">
<h1> Good {greet} Jenifer</h1>
</div>
);
}
export default Greet;
Greet.test.js
import React from 'react';
import ReactDom from 'react-dom';
import Greet from './Greet';
it('renders without crashing',()=>{
const div=document.createElement('div');
ReactDom.render(<Greet/>,div);
ReactDom.unmountComponentAtNode(div)
});
Aucun commentaire:
Enregistrer un commentaire