我需要一些帮助来格式化我的单元测试以从 testacular/karma 获得预期的结果
beforeEach( inject( function( customService, $httpBackend ){
service = customService;
$http = $httpBackend
;}))
it('should make a default call upon initialization',function(){
var modalObj = {
"id": null,
"contentId": null,
"isActive":false,
"websiteId":2000,
"createdByUserName":"haselton",
"text":"another micro",
"tags":[],
"something random":null,
"something else":3
},
requestObj = {"isActive":false,"tags":[],"websiteId":2000,"createdByUserName":"haselton","text":"another micro"},
mbObj = {};
$http.whenPOST('/url/of/call', [requestObj]).respond(
{
"id": 40,
"contentId": null,
"isActive": false,
"creationDate": "05/22/2013 14:24:14 PDT",
"lastModifiedDate": "05/22/2013 14:24:14 PDT",
"lastModifiedStatusDate": null,
"websiteId": 2000,
"createdByUserName": "haselton",
"text": "another micro",
"tags": []
}
);
然后我有一个服务会产生调用并返回一个承诺。以下是测试的其余部分:
mbObj = service.createEntry(modalObj); // returns a promise
mbObj.then(function(data){
console.log(data);
expect( angular.isNumber(data.id)).toBe(true);
expect(data.isActive).toBe(false);
expect(data.tags).toBe( 0 );
expect(data.websiteId).toBe(2000);
expect(data.createdByUserName).toBe("haselton");
expect(data.text).toBe("another micro");
});
$http.flush();
});
实现的承诺中的 console.log 没有通过,而是注销了 Angular 资源。这是一个屏幕截图:
关于我在这里做错了什么的任何想法?谢谢!