如何在单元测试中实例化angular js组件?

时间:2019-07-17 10:32:01

标签: angularjs karma-jasmine

我有一个用打字稿写的组件。我正在使用角度1.5。如何在测试用例中实例化此组件,以便可以测试组件内部的功能?

SFTPFileExplorerComponent.ts

export function SFTPFileExplorerComponent($rootScope) {
   let vm = this;

   vm.$onInit = () => {
      vm.currentDirectory = '';
      vm.files = {};
      vm.loading = false;
   }

   vm.setGridData = (connectionId: Number, currentDirectory: String, files: Object) => {
      vm.currentDirectory = currentDirectory;
      vm.files = files;
      vm.connectionId = connectionId;
      vm.filesLoaded = true;
   }

   vm.clearGridData = () => {
      vm.currentDirectory = '';
      vm.files = [];`enter code here`
      vm.connectionId = undefined;
   }
}

0 个答案:

没有答案