简体   繁体   English

业力单元测试用例未执行

[英]Karma unit test cases not getting executed

Karma unit test cases not getting executed. 因果关系单元测试用例无法执行。 There are no errors when I run the karma start my.conf.js command. 运行业力启动my.conf.js命令时没有错误。 There is nothing displayed in the DEBUG console. DEBUG控制台中没有任何显示。 Can anyone tell what can be the issue? 谁能说出问题所在? Here is my controller file : 这是我的控制器文件:

define('',['angular', 'moment', '../module'], function (ng, moment) {
  'use strict';

  ng
  .module('PatientRecord.controllers')
  .controller('PatientRecordController', ["$scope", "PatientRecordService", 'globalConfig',
      function ($scope, PatientRecordService, globalConfig) {
      $scope.addSubmitted = false;
      $scope.updateSubmitted = false;
      $scope.shareSubmitted = false;
      $scope.deleteSubmitted = false;
      $scope.patientRecords = [];
      $scope.modalRecord = {};
      $scope.sharedDoctors = [];
      $scope.potentialDoctors = [];
      $scope.medicalRecordsList = false;
      $scope.disableShareButton = true;
      $scope.validation = {
                              success:{
                                status:false,
                                message:""
                              },
                              error:{
                                status:false,
                                message:""
                              }
                          };

      $scope.file = {};
      var patientRecordService = new PatientRecordService();

      $scope.getRecord = function () {
        $scope.patientRecords.length = 0;
        patientRecordService.getRecords().then(function (response) {
          $scope.patientRecords = response;
          if ($scope.patientRecords.length) {
            $scope.medicalRecordsList = true;
          }
        });
        $('body').tooltip({
            selector: '.action-icon'
        });
      };

    $scope.addPatientRecord = function ($event) {
        $scope.addSubmitted =true;
        $scope.patientRecord.shared = [];
        $scope.patientRecord.file = $scope.addRecordFileUpload;
        patientRecordService.addPatientrecorddata($scope.patientRecord)
        .then(function (response) {
            $scope.addSubmitted = false;
            clearAddRecordFields();
            $("#add-record").modal("hide");
         $scope.getRecord();

          if(response){
            $scope.validation.success.status = true;
            $scope.validation.success.message = "Record added successfully";
            $scope.addForm.$setPristine();
            $scope.addForm.addRecordFileUpload.$error.required = true;
            $scope.patientRecord.medicalRecordTypeId ="";
            $scope.addRecordFileUpload = "";
          }else{
            $scope.validation.error.status = true;
            $scope.validation.error.message = "Confirmation is unsuccessful. Please try again";
          }
        });

      };

    $scope.closeAddDialog = function () {
      clearAddRecordFields();
      $("#add-record").modal("hide");
    };

    var clearAddRecordFields = function(){
      $scope.patientRecord.name = "";
      $scope.patientRecord.dateOfRecord = "";
      $scope.patientRecord.comments = "";
      $scope.patientRecord.medicalRecordType = "";
      $scope.patientRecord.addRecordFileName = "";

      $("#patientRecord_name").val("");
      $("#dateOfRecord").val("");
      $("#patientRecord_comments").val("");
      $("#medicalRecordType").val("");
      $("#addRecordFileName").html("");
    }





    var dispalyFileName = function (FileControlId, placeholderId) {
        if ($scope.currntFileObject) {
          $('#' + placeholderId).empty().html($scope.currntFileObject.name);
        }
    };


    $scope.openupdateModal = function (record) {
      $scope.modalRecord =  _.clone(record);
        var dateOfRecord = moment($scope.modalRecord.date_of_record).format("DD MMM, YYYY");
        $scope.modalRecord.date_of_record = dateOfRecord;
        $scope.disableShareButton = true;
        $("#updateRecordFileName").html("");
        //Get Shared Doctors Data
        patientRecordService.getSharedDoctorsByRecordId(record.id).then(function (response) {
        $scope.sharedDoctors = _.where(response, { isShared: true })
        $scope.potentialDoctors = _.where(response, { isShared: false })
        });
    };

    $scope.updatePatientrecord = function (index) {
        $scope.updateSubmitted = true;
        $scope.modalRecord.medicalRecordTypeId = $("#update_recordtype").val();
        $scope.modalRecord.file = $scope.updateRecordFileUpload;
        patientRecordService.updatePatientdata($scope.modalRecord)
        .then(function (response) {
            $scope.updateSubmitted = false;
            $scope.getRecord();
         });
   };

   angular.element("#selectDoctorToShare_foreditDialog").change(function () {
        var selectedDoctorId = $("#selectDoctorToShare_foreditDialog").val();
              $scope.$apply(function () {
                  if (selectedDoctorId != 0) {
                      $scope.disableShareButton = false;
                  } else {
                      $scope.disableShareButton = true;
                  }
                });
    });




    $scope.closeUpdateDialog = function () {
        $("#patientRecord_name").val("");
        $("#datetimepicker1").val("");
        $("#patientRecord_comments").val("");
        $("#medicalRecordType").val("");
        $("#addRecordFileName").html("");
        $("#modify-record").modal("hide");
        $scope.getRecord();
    };

    $scope.openShareDialog = function (data) {
          $scope.modalRecord = data;
          $scope.disableShareButton = true;
          patientRecordService.getSharedDoctorsByRecordId(data.id)
              .then(function (response) {
                  $scope.sharedDoctors = _.where(response, { isShared: true })
                  $scope.potentialDoctors = _.where(response, { isShared: false })
                });
      }

      $scope.sharePatientRecord = function(doctorDropdownId,recordId){
          $scope.shareSubmitted  = true;
       var selectedDoctorId = $("#"+doctorDropdownId).val();
       patientRecordService.sharePatientData(recordId, selectedDoctorId).then(function(response){
           $scope.shareSubmitted  = false;
        if(response){
          if(doctorDropdownId == "selectDoctorToShare_forShareDialog") {
            $("#share-record").modal("hide");
          }
          alert("Record shared successfully");


          patientRecordService.getSharedDoctorsByRecordId($scope.modalRecord.id)
          .then(function(response) {
            $scope.sharedDoctors = _.where(response, {isShared: true})
            $scope.potentialDoctors = _.where(response, {isShared: false})
          });
         $scope.disableShareButton = true;
       } else {
        alert("Something went wrong! Try again")
      }
      });
     };

      angular.element("#selectDoctorToShare_forShareDialog").change(function () {
      var selectedDoctorId = $("#selectDoctorToShare_forShareDialog").val();
              $scope.$apply(function () {
                  if (selectedDoctorId != 0) {
                      $scope.disableShareButton = false;
                  } else {
                      $scope.disableShareButton = true;
                  }
              });
      });


     $scope.OpenDeleteModal = function (data, index) {
        $scope.modalRecord = data;
        $scope.index = index;
        $("#delete-record-modal").modal("show");
    }

    $scope.deletePatientrecord = function (data, index) {
      $scope.deleteSubmitted  = true;
        var patientRecordService = new PatientRecordService();
      patientRecordService.deletePatientdata(data.id).then(function (response) {
          $scope.deleteSubmitted  = false;
        $("#delete-record-modal").modal("hide");
        $scope.getRecord();
        if(response){
          $scope.validation.success.status = true;
          $scope.validation.success.message = "Record deleted successfully";
        }else{
          $scope.validation.error.status = true;
          $scope.validation.error.message = "Record could not be deleted";
        }

      });
    };
    $scope.getRecord();
  }
  ]);

});

Test file for controller: 控制器的测试文件:

// Testing PatientRecordController
    define('',['angular', 'moment', '../module'], function (ng, moment) {
    describe("Controller: PatientRecordController", function() {
        // load the controller's module
      beforeEach(module('PatientRecord.controllers'));

      var PatientRecordController,
      scope;

    // Initialize the controller and a mock scope
      beforeEach(inject(function ($controller, $rootScope) {
          scope = $rootScope.$new();
          PatientRecordController = $controller('PatientRecordController', {
                                          '$scope': scope
                                    });
      }));

      // Check if controller is defined
      it("should have a PatientRecordController as controller", function() {
        expect(PatientRecord.controllers.PatientRecordController).toBeDefined();
        console.log('controllers defined');
      });
    });
    });

my.conf.js file: my.conf.js文件:

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

    // base path, that will be used to resolve files and exclude
    basePath: '',


    // frameworks to use
    frameworks: ['jasmine','requirejs'],


    // list of files / patterns to load in the browser
    files: [

      'app/modules/PatientRecord/controllers/PatientRecordController.js'

    ],


    // list of files to exclude
    exclude: [

    ],


    // test results reporter to use
    // possible values: 'dots', 'progress', 'junit', 'growl', 'coverage'
    reporters: ['progress','coverage','html'],

    htmlReporter: {
        outputFile: 'tests/units.html'
    },

    preprocessors: {
      // source files, that you wanna generate coverage for
      // do not include tests or libraries
      // (these files will be instrumented by Istanbul)
      'src/**/*.js': ['coverage']
    },

    // optionally, configure the reporter
    coverageReporter: {
      type : 'html',
      dir : 'coverage/',
      file:'coverageds.txt'
    },

    // 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: true,


    // Start these browsers, currently available:
    // - Chrome
    // - ChromeCanary
    // - Firefox
    // - Opera (has to be installed with `npm install karma-opera-launcher`)
    // - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`)
    // - PhantomJS
    // - IE (only Windows; has to be installed with `npm install karma-ie-launcher`)
    browsers: ['Chrome'],


    // If browser does not capture in given timeout [ms], kill it
    captureTimeout: 60000,


    // Continuous Integration mode
    // if true, it capture browsers, run tests and exit
    singleRun: false
  });
};

The problem is in the files section of your karma configuration file. 问题出在您的业力配置文件的“ files部分中。 First, you need to include all your application's library dependencies (like Jquery, Angular, Bootstrap) if you are using any. 首先,如果使用任何库依赖,则需要包括所有应用程序库依赖(例如Jquery,Angular,Bootstrap)。 Second, you need to include the files that you are testing. 其次,您需要包括要测试的文件。 Include your application's initialization file ( app.js ) and submodules first. 首先包含应用程序的初始化文件( app.js )和子模块。 Last, you need to include that actual tests themselves. 最后,您需要包括实际测试本身。 The order in which you include things does matter. 包含事物的顺序很重要。 A lot of people use RequireJS for this, but I don't think that's completely necessary unless you have a large and complex project. 很多人为此使用RequireJS,但是除非您有一个大型而复杂的项目,否则我认为这并不是完全必要的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM