Angular 9, Jasmine & Karma
Essentially we're trying to validate that when we try to go to the next page without filling out a required field, an error message appears. The positive case is that when we fill out a field that was originally empty, it should let us through. We're successfully able to query the input element, and set the value - and then even try sending a new event to trigger and input change to potentially cause the surveymodel logic to call the onValueChanged etc… but that does not seem to be happening. Tried wrapping the test in async, as well as
Codefixture.whenStable().then(() => { ... }
Code:
Codeit('should be able to navigate to next page once empty field is filled', () => {
const firstNameInput = querySelector('.sv_qstn input[aria-label="First Name"]')
firstNameInput.value = 'John'
firstNameInput.dispatchEvent(new Event('input'));
querySelector('.btn-navigation').click()
fixture.detectChanges()
// fail by default so I can debug
expect(true).toBeFalsy()
// expect(<some check that indicates on new page>)
})
...
function querySelector(query) {
return fixture.debugElement.nativeElement.querySelector(query)
}
Tossed a breakpoint into the middle of the test and the input field content is changed, but doesn't look like that update propagated to the SurveyModel. Thoughts?