Calculator meets use cases but fails test suite

[Edit: I moved this post from Project Feedback to freeCodeCamp Support as it felt more appropriate?]

Hi guys,

My pen is here: JavaScript Calculator.

The test suite has multiple failures, however AFAIK it passes all of the use cases and passes the test cases that are marked as failed.

Can anyone help?

Thanks,

Mark

I looked at the test failures and the code, and you are going to have to look at the error messages and fix some things. In other words, the tests are correct.

For instance, test #2 is failing because you have id="8" and not id="eight" as in the spec. Test #13 is failing because when you enter 5 * - 5, your calculator returns 0 instead of -25, as per the spec. You’ll need to chase down similar issues in the remaining tests as well.

I did notice you have the number 8, not the string “eight” for the button id.

I would suggest if you want debug code or tests then they should be unintrusive to the actual code. Keep tests and such out of the actual code. A few logs here and there are fine but your code is just harder to read because of all the extra code you have. I also think the toast component is throwing an error Uncaught ReferenceError: process is not defined

I didn’t confirm this, but I would be suspicious of the top-level variables you are using. For the most, you really want variables that are directly used by React for its view to be state-managed. For example, if I input some numbers and then run the test I get more failures than if I do not input anything first. And the errors I see show the numbers I did input in the “expect” asserts. Which might suggest there is an issue with the clear functionality.

But other than that I really didn’t look much at the code.

Thanks @jeremy.a.gray , I’ll double-check.

Looks like I mis-read story 13 so I’ll have to correct that.

I used the minus key purely for subtraction and the plusMinus key for negative values.

Thanks for the feedback @lasjorg but I can’t reproduce a ReferenceError, could you give a specific example?

Thanks.

Mark

I just get the error in the console when loading the page

index.js:4 Uncaught ReferenceError: process is not defined
    at index.js:4
(anonymous) @ index.js:4

If I click the code link I see this.

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./react-toastify.cjs.production.min.js')
} else {
  module.exports = require('./react-toastify.cjs.development.js')
}

Might not cause any issue with your actual calc code, but I just wanted to mention it.

I’m glad you did mention it - much appreciated thanks @lasjorg.

I re-checked and I do not get the error when running it outside of codePen; so I’ll have to look at codePen config to see what is causing it.

I assume it’s expecting a Node environment. It would likely work on something like CodeSandbox.

Thanks for all the feedback guys.

I have it working locally now but still fails some automated test cases (it passes them manually). This is because of how I create the buttons and their id’s etc. which the test suite fails to recognise.

I’ll mark this as solved and do some redesign work; thanks again all.

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