0
私は、コンポーネントのコントローラを模擬しています。ここでは、angularjsの$controllerProvider
を使用してコントローラを模擬しています。注入は正常に機能していますが、コントローラのコンテキストthis
は登録中でもundefined
です。コントローラは模擬した後でもユニットテストを定義していません
マイコンポーネント
import templateUrl from './pdf-export-modal.html.pug';
import './pdf-export-modal.less';
export default {
templateUrl,
bindings: {
onClose: '&',
},
controller: 'PdfExportModalCtrl',
};
と問題がES6の自動バインディングとしたコンポーネントのテストファイル
import angular from 'angular';
describe('component: pdf-export-modal',() => {
let $rootScope;
let $compile;
let scope;
let el;
let html;
let ctrl;
beforeEach(angular.mock.module('mainModule', ($controllerProvider) => {
$controllerProvider.register('PdfExportModalCtrl',() => {
ctrl = this;
console.log(ctrl, this); // both are undefined here
});
}));
beforeEach(inject((_$rootScope_, _$compile_) => {
$rootScope = _$rootScope_;
$compile = _$compile_;
scope = $rootScope.$new();
html = "<pdf-export-modal on-close='onClose'/>";
scope.onClose = jasmine.createSpy('onClose');
el = $compile(html)(scope);
scope.$apply();
}));
describe('selecting compact',() => {
// test
});
});