Click on "Run Test" problem

Hi,

Good day Everyone. So I’m on this project in Front-End Development the 25+5 Clock and I am using ReactJS, the problem is whenever I click the “Run Test” I’ve noticed that all button which has onClick was clicked and it changed the default value of the session and break length since it was clicked upon clicking the “Run Test”

The function “onIncrement” and “onDecrement” is the function for onClick event.

Here’s my code:


const App = () => {

  const [breaklength, setBreakLength] = useState(5);
  const [sessionlength, setSessionLength] = useState(25);
  const [play, setPlay] = useState(false);

  let currentBreakLength = breaklength;
  let currentSessionLength = sessionlength;

  const onIncrement = (e) => {
    let id = e.target.id;

    if (id === 'break-increment') setBreakLength((currentBreakLength += 1));
    else if (id === 'session-increment')
      setSessionLength((currentSessionLength += 1));
  };

  const onDecrement = (e) => {
    let id = e.target.id;

    if (id === 'break-decrement') {
      if (currentBreakLength > 1) setBreakLength((currentBreakLength -= 1));
    } else if (id === 'session-decrement') {
      if (currentSessionLength > 1)
        setSessionLength((currentSessionLength -= 1));
    }
  };

  const onReset = () => {
    setSessionLength(25);
  };

  return (
    <div className='App'>
      <div className='wrapper'>
        <TimerControl
          onIncrement={onIncrement}
          onDecrement={onDecrement}
          sessionlength={sessionlength}
          breaklength={breaklength}
        />
        <TimerDisplay
          onReset={onReset}
          sessionlength={sessionlength}
          breaklength={breaklength}
        />
      </div>
    </div>

  );

};

I hope someone can help me.

That is just how the test interacts with your app. It has to interact with the app to test it (click buttons, fire off events, check the DOM for valid output)

Not sure what the issue is but it would help if you linked to a live version of your app on something like Codesandbox or Codepen.

1 Like

Hi,

Here is the link for my codepen

Codepen

You will notice upon clicking the “Run Test” the break and session length have changed.

You have passed 11/29 test,
check your unpassed tests

Hi,

My bad, I think it is part of the testing. But it’s okay now and I have completed the project.

Thank you for your reply guys.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.