lundi 8 mai 2017

Unit tests for POST api restangular

I am writing unit test case for rest-angular post api,here is my factroy code which will call post post api

return {
post: function (data) {
    return students
        .all(data.studentId)
        .customPOST(data, 'students')
        .then(function (res) {
            return res.body;
        })
        .catch(function (err) {
            return $q.reject(err.data);
        });
}
}

And I have wrote this test:

it('Should be able to post using post api', function (done) {

    var mockStudents = StudentsBackend.get(studentId);
    // respond with the mock
    $httpBackend.expectPOST('/res/students/' + studentId + '/students').respond(201);
    var promise = Students.get(studentId);

    promise.then(function (students) {
        expect(students).toBeDefined();

        expect(students).toEqual(mockStudents);
        done();
    });

    $httpBackend.flush();
});

It is failing , Is anyone can help? Thank You

Aucun commentaire:

Enregistrer un commentaire