假设这是我试图测试的功能:
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
?