chai-http errors out when return status code is 501

49 views
Skip to first unread message

Fabio Alejandro Gómez Díaz

unread,
Feb 5, 2016, 4:51:42 PM2/5/16
to Chai.js
Hi,

In my node server, one of my requests returns 501 for a functionality that we don't support.

In my test I try to make an http request to it using chai-http to test that it indeed is not supported. Here is the request

exports.bind = function (req, res) {
    res.status(501).send('Not supported');
};

Then when running the test using Mocha I get the following

  Binding

      1) should specify bind as unsupported



  0 passing (1s)

  1 failing


  1) Binding should specify bind as unsupported:

     Error: Not Implemented

      at Test.Request.callback (node_modules/chai-http/node_modules/superagent/lib/node/index.js:792:17)

      at IncomingMessage.<anonymous> (node_modules/chai-http/node_modules/superagent/lib/node/index.js:990:12)

      at endReadableNT (_stream_readable.js:903:12)

Here is what the test looks like

it('should specify bind as unsupported', function (done) {

    chai.request(config.url)

        .put('/v2/service_bindings/bindingId')

        .set(utils.Content_Type, utils.application_json)

        .set(utils.Accept, utils.application_json)

        .then(function (res) {

            console.log(res.body);

            expect(res).to.have.status(501);

            done();

        })

        .catch(function (err) {

            done(err);

        });

});


It doesn't even get to the log on the then() block because it errors out with message shown above.

Is there a way to successfully make sure that the above shows up as successful on the test report? I am new to chai and chai-http so please feel free to point me in the right direction
Reply all
Reply to author
Forward
0 new messages