2015-12-18 1 views
2

Мы разрабатываем программу, управляемую тестом в машинописном машинописном тексте. Это наш тест с жасмином:

import IDifferentialPilotService = DifferentialPilot.IDifferentialPilotService; 
import Ev3DifferentialPilotService = DifferentialPilot.Ev3DifferentialPilotService; 
import IHttpService = ng.IHttpService; 

describe("restClientService integration test: ", function() { 

    // sut 
    var ev3DifferentialPilotService: IDifferentialPilotService; 

    //doc 
    var http: IHttpService; 

    beforeAll(function() { 
     angular.mock.inject(function ($http: IHttpService) { 
      this.http = $http; 
     }); 
     ev3DifferentialPilotService = new Ev3DifferentialPilotService(http); 
    }); 

    it("robot should run 5 m", function() { 
expect(ev3DifferentialPilotService.runDistance(5)).toBe("success"); 

    }); 

}); 

класс Ev3DifferentialPilotService который тестируется выглядит так:

namespace DifferentialPilot { 
    "use strict"; 

    import IHttpService = ng.IHttpService; 

    export class Ev3DifferentialPilotService implements IDifferentialPilotService { 
     private http: IHttpService; 

     static $inject = ['$http']; 
     constructor($http: IHttpService) { 
      this.http = $http; 
     } 

     public runDistance(runDistance: number): string { 
      this.http({ 
       method: "POST", 
       url: "10.0.0.44:8080/differentpilot/run/5" 
      }).then(function successCallback(response: any) { 
       return "success"; 
      }, function errorCallback(response: any) { 
       return "error"; 
      }); 

      return undefined; 
     } 
    } 
} 

Как вы можете видеть, мы хотим внедрить в нашем тесте $http -SERVICE, так что Ev3DifferentialPilotService может получить Http-сервис как параметр и использовать его в своем методе runDistance. Когда мы регистрируем this.$http -Object в Ev3DifferentialPilotService, тогда получаем undefined, что означает, что инъекция не удалась. В соответствии с этим тест также терпит неудачу.

Im регистрирующий Ev3DifferentialPilotService как сервис в App.js:

var app = angular.module("AngularDifferentialPilotModule", []); 
app.service("ev3DifferentialPilotService", DifferentialPilot.Ev3DifferentialPilotService); 

И мы используем все эти вещи в нашем karam.conf.js:

// Karma configuration 
// Generated on Thu Dec 17 2015 14:02:38 GMT+0100 (Mitteleuropäische Zeit) 

module.exports = function (config) { 
    config.set({ 

     // base path that will be used to resolve all patterns (eg. files, exclude) 
     basePath: '', 


     // frameworks to use 
     // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 
     frameworks: ['jasmine'], 


     // list of files/patterns to load in the browser 
     files: [ 
      "bower_components/angular/angular.js", 
      "bower_components/angular-mocks/angular-mocks.js", 
      "src/Ev3DifferentialPilotService.js", 
      "spec/*.spec.js", 
      "src/app.js" 
     ], 

     // list of files to exclude 
     exclude: [], 


     // preprocess matching files before serving them to the browser 
     // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 
     preprocessors: {}, 


     // test results reporter to use 
     // possible values: 'dots', 'progress' 
     // available reporters: https://npmjs.org/browse/keyword/karma-reporter 
     reporters: ['progress'], 


     // web server port 
     port: 9876, 


     // enable/disable colors in the output (reporters and logs) 
     colors: true, 


     // level of logging 
     // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 
     logLevel: config.LOG_INFO, 


     // enable/disable watching file and executing tests whenever any file changes 
     autoWatch: false, 


     // start these browsers 
     // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 
     browsers: ['Firefox'], 


     // Continuous Integration mode 
     // if true, Karma captures browsers, runs the tests and exits 
     singleRun: false, 

     // Concurrency level 
     // how many browser should be started simultanous 
     concurrency: Infinity 
    }) 
} 

Кроме того, мы используем TSconfig, который выглядит так :

{ 
    "compilerOptions": { 
    "module": "commonjs", 
    "noImplicitAny": true, 
    "removeComments": true, 
    "preserveConstEnums": true, 
    "sourceMap": true 
    } 

И где ошибка? Может кто-нибудь мне помочь?

ответ

Смежные вопросы