我正在尝试组合一些组件的测试。我有以下
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
}))
})
item-selector
的控制器采用activate()
方法。我如何从测试中调用它? $scope
似乎不包含任何引用。
答案 0 :(得分:5)
let ctrl = element.controller('item-selector')