lundi 30 mai 2016

I am Getting error when i am testing the controller with the Nock

Hi i want to mock the controller function using the npm Nock module. I am Getting the error as Cannot read property 'json' of undefined. Here My code is

branchController.js:

exports.create = function (req, res) {
    var branch = new branch(req.body);

    Branch.save(function (err) {
        if (err) {
            return res.status(400).send({
                message: errorHandler.getErrorMessage(err)
            });
        } else {
            res.json(branch);
        }
    });
};

branchtest.js

describe('Branch Controller Testing', function () {
    it('should create a new Branch', function (done) {
        nock('http://localhost:4000',{
        },options)
            .matchHeader('accept', 'application/json')
            .post('/api/branch', {
                street1: 'Unforgiven II'
            })
            .reply(200, {'Content-Type': 'application/json'});
            branch.create(function(error, response) {
            expect(response).to.eql('OK')
            done()
        })

    })
})

Please can anybody help me on this issue.

Aucun commentaire:

Enregistrer un commentaire