如何测试函数使用Jasmine返回一个对象

时间:2017-04-29 02:11:59

标签: angularjs jasmine karma-jasmine

假设这是我试图测试的功能:

self.fetch = {
 things: function() {
   return $http.get("/api/things/")
     .then(function(response) {
         return response.data;
   });
 }
};

这是我目前的测试:

it('fetch.thingss() should GET to /api/things/ and return object', function() {
    mockBackend.expectGET("/api/things/").respond(204, {data: {th: 'th'}});

    var p = BaseService.fetch.things();


    p.then(function(response){
        expect(response.data).toEqual({th: 'th'});
       });

    mockBackend.flush();
});

但目前这只是测试response.data应该是什么。如何测试函数返回response.data

0 个答案:

没有答案