我想通过切换点击测试isMultipleInvoice状态变为false。我模拟切换点击调用dispatchEvent
,triggerEventHandler
与click
,input
,change
,但isMultipleInvoice状态始终为true。我已经在评论行中包含了我尝试的所有内容。
视图:
<md-slide-toggle class="gregreger" [(ngModel)]="isMultipleInvoice">Default Name & Address</md-slide-toggle>
试验:
it('should to be false isMultipleInvoice', fakeAsync(() => {
expect(component.isMultipleInvoice).toBeTruthy("isMultipleInvoice must true")
let toggle = fixture.debugElement.query(By.css(".gregreger"))
toggle.nativeElement.dispatchEvent(new Event('change'))
//toggle.nativeElement.dispatchEvent(new Event('input'))
//toggle.triggerEventHandler("change",null)
//toggle.nativeElement.click()
//document.createEvent('Event');
fixture.detectChanges()
tick()
//tick(500)
expect(component.isMultipleInvoice).toBeFalsy("toggle should update model")
}))