我想测试ng-if
中没有ng的输入是否存在 - 如果测试完全通过但不与ng-if
通过。Angular 1/ui-select/Jasmine - 测试元素是否存在于ng中 - 如果
在我的模板,我有:
<div ng-if="$ctrl.doShowAir">
<input class="form-control" type="text">
</div>
的doShowAir
是一个功能doShow()
内的变量在以前的UI选选择的选择,当它应该是true
<ui-select ng-model="$ctrl.parking.parkingType"
on-select="$ctrl.doShow()">
<ui-select-match>
<span>{{ $select.selected.label }}</span>
</ui-select-match>
<ui-select-choices repeat="item in $ctrl.projectReferences.parkingType | filter: { label: $select.search }">
<span ng-bind-html="item.label"></span>
</ui-select-choices>
</ui-select>
功能:
doShow() {
this.doShowAir = (this.parkingType.labelKey === 'parking_type.air')
}
而uni t检验:
import angular from 'angular'
import 'angular-mocks'
let scope
let rootScope
let compile
let htmlElement
let ctrl
fdescribe('projectExteriorParking',() => {
beforeEach(() => {
angular.mock.module('ProjectExteriorParkingModule')
angular.mock.module('ui.select')
})
beforeEach(inject((_$compile_, _$rootScope_) => {
rootScope = _$rootScope_
compile = _$compile_
scope = rootScope.$new()
scope.parking = {}
htmlElement = compile(`<project-exterior-parking parking="project.realEstateProjectProduct.parkings"></project-exterior-parking>`)(scope)
rootScope.$digest()
}))
beforeEach(inject(($componentController) => {
let bindings = {
parking: {},
projectReferences: {}
}
ctrl = $componentController('projectExteriorParkingModule', null, bindings)
}))
it('should contain two input',() => {
const inputItems = htmlElement.get(0).querySelectorAll('input')
expect(inputItems.length).toBe(2)
})
})
我如何可以模拟该变量shouldShowAir
是真实的,还是模拟的用户界面,选择因为我没有访问doShow()
函数调用函数的选择on-select="$ctrl.doShow()"
。 或者你如何“手动”除了输入添加到测试和编译它<project-exterior-parking parking="project.realEstateProjectProduct.parkings"></project-exterior-parking>
1.什么是你想用做方法的值:'CTRL = $ componentController(“projectExteriorParkingModule”,空,绑定)'在第二个' beforeEach'块?这是试图让上面的编译组件的控制器?你可以用'htmlElement.controller('projectExteriorParking')'获得元素控制器 – kidroca