2015-07-10 69 views
0

我有一个使用业力的单元测试的问题。Karma Angular.js单元测试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 
+0

是否定义了'envConfig.restUrl'? –

+1

没有问题 - 你期待PUT调用,但永远不会发生 - '$ httpBackend.flush()'试图刷新所有的请求,但没有挂起的请求。 –

+0

@KrzysztofSafjanowski看看正在请求的URL =>'PUT undefinedcustomers/1' –

回答

0

你没有定义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(); 
+0

它被定义。 expectGET测试成功 – kret

+0

@ kret否 - 它没有被定义 - 显示更多/完整的测试代码,所以我们可以尝试找到错误来源 –

+0

好的,我应该把函数调用放在'it'部分吗? – kret

相关问题