[英]How to access component controller when testing?
I am trying to put together some tests of a component. 我正在尝试对组件进行一些测试。 I have the following 我有以下
describe(`selecting an item`, () => {
let element, $scope;
beforeEach(module('my-app'))
beforeEach(inject(($compile, $rootScope) => {
$scope = $rootScope;
element = $compile(`
<item-selector parent-id="pid">
</item-selector>
`)($scope)
//call $ctrl.activate() on the component's controller
}))
})
the controller for item-selector
has an activate()
method. item-selector
的控制器具有activate()
方法。 How can I invoke it from my test? 如何从测试中调用它? $scope
doesn't seem to contain any reference. $scope
似乎不包含任何引用。
let ctrl = element.controller('item-selector')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.