jeudi 10 septembre 2020

Testing Node API using Mocha/Chai

The function should be testing three conditions 1)status is 200 2)response is in HTML form 3)text of the response is equal to index.html. My Code is as follow

const index = fs.readFileSync('../index.html');
describe('GET / path', () => {
    it('it should GET the index.html' ,(done) => {
        chai.request(server)
            .get('/')
            .end((err, res) => { 
                res.should.have.status(200); 
                res.body.should.be.html;
                res.text.should.be.eql(index);
                done();
            });
    });
});

But this function is giving an error

 1) Going through the routes
   GET / path
     it should GET the index.html:
 Uncaught AssertionError: expected {} to have headers or getHeader method
  at Assertion.<anonymous> (node_modules\chai-http\lib\http.js:224:40)
  at Assertion.propertyGetter (node_modules\chai\lib\chai\utils\addProperty.js:62:29)
  at Object.get (<anonymous>)
  at Object.proxyGetter [as get] (node_modules\chai\lib\chai\utils\proxify.js:98:22)

Is there any problem with my third condition??

Aucun commentaire:

Enregistrer un commentaire