0
ng-ifの内部にある入力の存在をテストしたい場合は、ng-ifを使用します。 ng-ifはDOMから要素を削除するので正常です。私のテンプレートで角1 /ジャスミン - ng-if内にテストエレメントが存在する場合
私が持っている:
<div ng-if="$ctrl.shouldShowAir">
<input class="form-control" type="text">
</div>
私のコンポーネントで
shouldShow() {
this.shouldShowAir = (this.parkingType.labelKey === 'parking_type.air')
}
ユニットテスト
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)
})
})
変数i shouldShowAir
であることをシミュレートすることができますどのようにtrue