mardi 8 décembre 2015

Error when executing Unit Test for AnjularJS

Iam new to AngularJS. Iam attempting to write a UTP using Karma. The code goes like this:

(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;
            });

        });
    });
})();

I run the test using grunt the command is Grunt test. ButI get the below error:

  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)

The endpoint URL of the web service it is trying to connect is CORRECT. Can anyone please tell me if i'm doing everything the correct way.

Aucun commentaire:

Enregistrer un commentaire