Thursday, 20 April 2017

How to use Nock with mocha

I am using nock with mocha for restapi testing. but when i used .reply(200,"msg" :"url matched").they only check 200 response in server coding. how to used in proper way. my code are given below: its a negative case. actualy they show 404 response. but when i using 200 they passed this testcase.

it("test case for /hotel/:id/location api", function (done) {
        nock("http://localhost:3010")
            .get('/hotel/1/location')
            .reply(200, {'msg': 'response matched'});
        server
            .get("/hotel/1/location")
            .expect("Content-type", /json/)
            .end(function (err, res) {
                if (res.success == false) {
                    res.status.should.equal(200);
                }
                if (err)
                {
                    res.body.error.should.equal(true);
                }
                done();
            });
    nock.cleanAll();
    });
});



via pjrocks

No comments:

Post a Comment