lundi 29 juillet 2019

I am having hard time writing Jest test for timer

I am trying to write jest test for react-countdown-now timer. It should be pretty simple, but i am new to jest and i am having hard time writing it.

import React from 'react';
import ReactDOM from 'react-dom';
import Countdown, { zeroPad } from 'react-countdown-now';
import "./TimeOut.scss";
 
const renderer = ({ minutes, seconds, completed }) => {
  return <div><span>{zeroPad(minutes, 2)}:{zeroPad(seconds, 2)}</span></div>;
};

class Timer extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      timeout: props.timeout * 60 * 1000
    };
  }

  render() {
    return (
      <Countdown
        date={Date.now() + this.state.timeout}
        renderer={renderer}/>
    );
  }
}

export default Timer;

Aucun commentaire:

Enregistrer un commentaire