Angular unit testing to check if a button is disabled

I just started learning about angular unit testing I am trying to test if the submit button is disabled when the textarea is empty.

I tried this

  it('should test if submit button is disabled when the form is invalid', () => {
fixture.detectChanges();
let comment = component.feedbackForm.controls["comment"];
comment.setValue("good");
const addCommentBtn = fixture.debugElement.query(By.css('button'));
expect(addCommentBtn.nativeElement.getAttribute('disabled')).toEqual('');
});
});

but it says native element is null . What am i doing wrong

html

      <textarea
      formControlName="comment"
      Inputtype="text"
    ></textarea>
    <button
      type="submit"
      [disabled]="disableButton$ | async"
    >
      {{ Submit }}
    </button>

ts

feedbackForm = new FormGroup({
comment: new FormControl('', [this.validateFeedback]),
});


Read more here: https://stackoverflow.com/questions/64399745/angular-unit-testing-to-check-if-a-button-is-disabled

Content Attribution

This content was originally published by user10183910 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: