2
我在我的頭用這個來獲取所有數據,我分析我的控制器(的toJSON)標題:單元測試角分頁
X-Pagination:{"current_page":1,"per_page":10,"total_pages":16,"sub_count":10,"total_count":159}
var parsingHeader = angular.fromJson(vms.headers('X-Pagination'));
_this.current_page = parsingHeader.current_page;
_this.per_page = parsingHeader.per_page;
_this.total_pages = parsingHeader.total_pages;
_this.total_count = parsingHeader.total_count;
我要測試的這款:
$httpBackend
.whenGET('http://localhost:3000/vms.json?page=1')
.respond(function(method, url, data, headers){
...
});
我有一些錯誤: 'null'不是一個對象(評估'parsingHeader.current_page'),...
什麼是測試這個最好的過程?
你能告訴我一個例子嗎?在我的回覆或網址? – user3703539
閱讀angular docs:https://docs.angularjs.org/api/ngMockE2E/service/$httpBackend whenGet支持頭文件...參見'whenGET(url,[headers],[keys]);' – Ammar
'$ httpBackend.whenGET('http:// localhost:3000/vms.json?page = 1',[{'X-Pagination':{'current_page':1,'per_page':'10','total_pages':' 16','sub_count':'10','total_count':'159'}}]).respond(function(method,url,data,headers){console.log(data);});' 它返回:沒有更多的請求 – user3703539