February 2019
Beginner
694 pages
18h 4m
English
The final set of tests that we will build will target our two forms, and simulate a user entering values into the form fields, as well as clicking on the submit button. The first test is for our standard form, as follows:
it("should set a value on the form, and click submit", () => {
let submitSpy = spyOn(app, 'onSubmit');
fixture.detectChanges();
fixture.whenStable().then(() => {
const domElement = fixture.debugElement.nativeElement;
let formInput = domElement.querySelector(".form-group input");
expect(formInput.value).toBe(`Your Name`);
formInput.value = 'Updated Value';
let submitButton = domElement.querySelector('#submit-button-button'); expect(submitButton).toBeTruthy(); submitButton.click(); expect(submitSpy).toHaveBeenCalled(); ...Read now
Unlock full access