My .post() function checks for empty required fields:
if(issue_title == "" || issue_text == "" || created_by == "") {
res.json({ "Error": "missing inputs" });
} else {
// Find project and add NEW issue
Project.findOne({ "project_title": project }, function (err, doc) {...}
My Chai Test, tests for missing fields and tests that { "Error": "missing inputs" } is returned.
However this never happens as the form in the front-end has validation, to ensure these fields are always complete.
BUT the chai test by-passes the front-end form and tests the .post() directly (?).
test('Missing required fields', function(done) {
chai.request(server)
.post('/api/issues/test')
.send({
//issue_title: 'Title', // commented out to simulate being missing
//issue_text: 'issue', // commented out to simulate being missing
//created_by: 'Functional Test - Missing required fields', // commented out to simulate being missing
assigned_to: 'Chai and Mocha',
status_text: 'Text1'
})
.end(function(err, res) {
console.log(res.body); // {}
assert.equal(res.json, { "Error": "missing inputs" });
done();
})
});
console.log(res.body); returns { }.
Can anyone explain why the { } is empty?