How does Chai testing work?

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) {
          //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" });

console.log(res.body); returns { }.
Can anyone explain why the { } is empty?

1 Like

This is where you plan your assertions. More in docs here
Let’s say you plan for 1 assertion


and if no assertions have been made, then it fail the tests, saying I was expecting an assertion to be made

Bluestacks Lucky Patcher