如何伪造点击茉莉花测试中的md-slide-toggle

时间:2018-01-25 09:07:13

标签: angular testing jasmine

我想通过切换点击测试isMultipleInvoice状态变为false。我模拟切换点击调用dispatchEventtriggerEventHandlerclickinputchange,但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")
}))

0 个答案:

没有答案