![](/img/trans.png)
[英]Angular.js promise not resolving when unit testing service with karma
[英]Karma Angular.js unit test expectPUT
我使用業力進行單元測試時遇到問題。
$httpBackend.expectPUT(envConfig.restUrl + 'customers/1').respond(200);
it('should update"customer details" model', function() {
expect(scope.customerDetails).toBeUndefined();
$httpBackend.flush();
和響應:
Error: Unsatisfied requests: PUT undefinedcustomers/1
at Function.$httpBackend.verifyNoOutstandingExpectation
您的envConfig.restUrl
未定義。
根據@KrzysztofSafjanowski注釋,您也不在調用可能會執行該PUT
請求或手動執行的函數。 將其更改為whenPUT
可能會解決此問題:
$httpBackend.whenPUT(envConfig.restUrl + 'customers/1').respond(200);
it('should update"customer details" model', function() {
expect(scope.customerDetails).toBeUndefined();
$httpBackend.flush();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.