简体   繁体   English

Karma Angular.js单元测试ExpectPUT

[英]Karma Angular.js unit test expectPUT

I've got a problem with unit tests using karma. 我使用业力进行单元测试时遇到问题。

  $httpBackend.expectPUT(envConfig.restUrl + 'customers/1').respond(200);
  it('should update"customer details" model', function() {
      expect(scope.customerDetails).toBeUndefined();
      $httpBackend.flush();

and the response: 和响应:

 Error: Unsatisfied requests: PUT undefinedcustomers/1
 at Function.$httpBackend.verifyNoOutstandingExpectation 

Your envConfig.restUrl is not defined. 您的envConfig.restUrl未定义。

As per @KrzysztofSafjanowski comment you're also not calling a function which might do that PUT request or doing that manually. 根据@KrzysztofSafjanowski注释,您也不在调用可能会执行该PUT请求或手动执行的函数。 Changing it to whenPUT might fix that : 将其更改为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