what am I supposed to fill in the assert statements
test("Convert 10L (valid input)", function(done) {
chai
.request(server)
.get("/api/convert")
.query({ input: "10L" })
.end(function(err, res) {
assert.equal(res.status, 200);
assert.equal(res.body.initNum, 10); // <-
// here I enter a invalid number then what should I enter here
assert.equal(res.body.initUnit, "l");
assert.approximately(res.body.returnNum, 2.64172, 0.1);
assert.equal(res.body.returnUnit, "gal");
done();
});
});
@Advitya-sharma, try with input 10l (not capital). If it solves, and even after if you want to put also 10L, you need to do some more work on the main app
no I’m not asking about this
what I’m interested in knowing is
if I enter a invalid number eg 34kx
then what I need to enter in assert.equal(res.body.initUnit, "l");
and assert.equal(res.body.returnUnit, "gal");
if you put 34l your code will give a valid output as per logic in the main app, and the output will be in gal. Now, if you put 34kx it will return an error as you set in your main app.
So, if you test code with wrong input, your assert need to fill something like this, assert.noEqual(res.body.yourTestUnit, 'l')
or assert.equal(res.body.yourTestUnitHere, 'yourErrorTextHereAsYouSetInYourApp')
@Advitya-sharma,
Since, -g- is not defined , it would result invalid unit and should not go for further check to convert the item, rejecting one part - you can reject the whole thing with null/undefined value
TypeError: Cannot read property 'toLowerCase' of undefined at ConvertHandler.convert (/app/controllers/convertHandler.js:125:22) at /app/routes/api.js:26:38
this is the output for wrong unit input. The problem is inside your main app, not in the testing part, try to understand the error, and fix it from there, then come back to the testing part
I followed the route you’re working on, you’we testing ‘/api/convert’ and sending the query {input:'32g'}, So, the main app link is your-site-url/api/convert?input=32g, that showed the error @Advitya-sharma