执行AnjularJS的单元测试时出错

时间:2015-12-08 22:29:03

标签: angularjs unit-testing gruntjs karma-runner karma-mocha

我是AngularJS的新手。我尝试使用Karma编写UTP。代码如下:

(function () {
    'use strict';

describe('Document Service', function () {
    var SEARCH_URL = '/documents';
    var DETAILS_URL = '/documents/111111';
    var DOC_HISTORY_URL ='/documents/history';

    var Document_global;
    var Document;

    beforeEach(function() {
        module( 'lens.globals' );
        module( 'lens.util' );
        module( 'lens.integration' );
        module( 'lens.models', function( $provide ) {
            $provide.value( 'Config', mockConfig );
        });
        module( 'ngLodash' );
        module( 'ui.router' );
        module( 'lens.document', function( $provide ) {
            $provide.value( 'Labels', mockLabels );
            $provide.value( 'PubSub', mockPubSub );
        });
    });

    beforeEach( inject( function ( _Document_global_, _Document_ ) {
        injectCoreServices();

        Document_global = _Document_global_;
        Document = _Document_;
    }));
-------
     -------- 
 describe( 'Document Service() DocHistory', function () {
            it( 'Should send the client security check query to the server', function () {
                var bResult = false;
                $httpBackend.expectGET( DOC_HISTORY_URL + '?id=11111' ).respond( true );
                Document.getHistory( 11111 ).then( function ( response ) {
                    bResult = response;
                });
                $httpBackend.flush();
                expect( bResult ).to.be.true;
            });

        });
    });
})();

我使用grunt运行测试,命令为Grunt test。但我得到以下错误:

  Document Service() DocHistory
      × Should send the client security check query to the server
        Chrome 46.0.2490 (Windows 7 0.0.0)
      Unexpected request: GET http://localhost:8080/GlobalAPI/dms/secured/documents/history?id=11111
      Expected GET /documents/history?id=11111
      Error: Unexpected request: GET GlobalAPI/dms/secured/documents/history?id=11111
      Expected GET /documents/history?id=11111
          at $httpBackend (C:/Dev/workspaces/DMSUIDevelopment/webui/client/bower_components/angular-mocks/angular-mocks.js:1244:9)
          at sendReq (C:/Dev/workspaces/DMSUIDevelopment/webui/client/bower_components/angular/angular.js:10558:9)
          at serverRequest (C:/Dev/workspaces/DMSUIDevelopment/webui/client/bower_components/angular/angular.js:10268:16)
          at processQueue (C:/Dev/workspaces/DMSUIDevelopment/webui/client/bower_components/angular/angular.js:14792:28)
          at C:/Dev/workspaces/DMSUIDevelopment/webui/client/bower_components/angular/angular.js:14808:27
          at Scope.$eval (C:/Dev/workspaces/DMSUIDevelopment/webui/client/bower_components/angular/angular.js:16052:28)
          at Scope.$digest (C:/Dev/workspaces/DMSUIDevelopment/webui/client/bower_components/angular/angular.js:15870:31)
          at Function.$httpBackend.flush (C:/Dev/workspaces/DMSUIDevelopment/webui/client/bower_components/angular-mocks/angular-mocks.js:1543
          at Context.<anonymous> (C:/Dev/workspaces/DMSUIDevelopment/webui/client/app/document/Document.service.spec.js:145:30)

它尝试连接的Web服务的端点URL是CORRECT。任何人都可以告诉我,我是否正确地做了一切。

0 个答案:

没有答案