benjamincharity
5/23/2017 - 8:44 PM

Trigger input events when updated for tests.

Trigger input events when updated for tests.

  const updateFormValue = (cssSelector: any, value: string | number | boolean, elementType = 'input') => {
    const debugElement = fixture.debugElement.query(By.css(cssSelector));
    const formElement = debugElement.nativeElement;

    switch (elementType) {
      case 'input':
        formElement.value = value;
        formElement.dispatchEvent(new Event('input', {
          'bubbles': true,
          'cancelable': true
        }));
        break;
      case 'checkbox':
        formElement.checked = true;
        formElement.dispatchEvent(new Event('change', {
          'bubbles': true,
          'cancelable': true
        }));
        break;
    }

  };