Metric-Imperial Converter input validation

Hi all, I am doing the Metric-Imperial Converter, but I cannot seem to pass the tests:

  • If the unit of measurement is invalid, returned will be 'invalid unit' .
  • If the number is invalid, returned will be 'invalid number' .
  • If both the unit and number are invalid, returned will be 'invalid number and unit' .

All other tests are passing. My solution is definitely not the cleanest, but I went over it a couple times, as well as tried to enter different values, and it seems to work as expected. What I do notice, is that if I console.log the “input” in api.js, then the last two lines when I “check” the tests is “undefined”. I have no idea what would need to be entered in input to simulate that. I manually tried all the other values that appeared there, and those all work fine.
I tried to find the values that the tests are using online, but I could not get to them, and I guess I just cannot imagine the inputs that are failing.

One other thing I do notice, is that the UI refreshes only when valid values (example → put in 1gal → works, → try to put in blank value → still shows result for the 1gal conversion.

Here is my code - https://repl.it/@Aigarsss/boilerplate-project-metricimpconverter

Thank you in advance.

Totally unrelated:
Sometimes when I run it, all the tests in the console pass, but repl crashes and wont load the page. Not sure if its somethin im doing, or something wronf with repl. Crashes don’t happen if I comment out the runner.run(); line.

Challenge: Metric-Imperial Converter

Link to the challenge:

Welcome, Aigarsss.

I think the tests are looking for a JSON response, not plain text.

PS: if you open the browser console, while submitting your link, you will see the failed assertion errors with more detail

Hope this helps

1 Like

Thanks, the second tip is handy, did not think of it. Will keep investigating.

edit:
well this is interesting… If I remove the .status(400) from the res., then I can pass the tests, but then I fail the functional tests, as it requires to return the 400 code? Or did I dream that up myself? I could have sworn I saw it somewhere.

I did pass it when I:

  1. removed the status(400) from res.status(400).send(). Maybe I made it up that that was necessary. The test could not be passed with this status code, errored in the console.
  2. Changed the functonal tests to assert.equal(res.text, "invalid "); . Before I checked res.status, 400.

Passing now, but feels a bit hacky.

1 Like

‘looking for a JSON response’ is a very helpful hint. Helped me a lot