簡體   English   中英

Karma Angular.js單元測試ExpectPUT

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM