My calculator seems to be working correctly, but the tests claim that even basic functions such as “clear” are not working.
I have a live demo at React Calculator . It utilizes React 17.
Rather than posting source here, I assume folks could just view the source in the demo.
It seems from the results that the test suite is having trouble clicking the buttons. That’s just my guess though
I am new with React so not easy to understand it, but shouldn’t your
switch have a default case
default: state ? I mean, not need to return it in the function, am I right?
It looks like your app is not really working fine, it is not reseting the state I guess and it is not handling negative numbers, but not sure what the problem is. I hope this help you in some way.
I would need to test it myself to come with some ideas, I still need practices.
It’s good form, but not necessary. In the end, the reducer returns the new state.
I cannot see the code. Hw do you access it?
View Source. The code is in the file calculator.jsx. Hre’s a direct link- calculator.jsx
I think since your using your
Digit class instead of the
button element the test suite is giving problems. I see that the
Digit class is a button but I recommend that you should try to replace the
When running the tests, the display changes. So, my code is responding.
Digit is a just a React component which returns a button. If you use the inspector, you can see that all of the keys are buttons.
It really helps if you post the code using something like StackBlitz or CodeSandbox. So people can actually test the code properly.
If I move all the components out of
Calculator and pass down dispatch it passes all but test 13
The sequence “5 * - 5” = should produce an output of “-25” : expected ‘20’ to equal ‘-25’
I’m afraid I don’t understand.
Wait a minute, I think I understand.
Move all the button components out of the
Calculator component and pass
dispatch down as a prop to each of them.
I would generally suggest you do not declare components inside components. It can often lead to state bugs or issues with re-renders.
Also, I’d really suggest you use something like Vite and not CDN links.
OK. I understand and I fixed the code so it passes everything but #13, but that’s another issue. Thanks.