February 2019
Beginner
694 pages
18h 4m
English
Let's now write a set of tests for our React form. The first test that we will write will be to check that the input element has been set to the correct initial value. Again, this test is important in the life cycle of forms, since in a real-world application, we could be setting these initial values from an existing database record. Our test is as follows:
it('should render a form with default value ', () => {
let domNode = ReactDOM.findDOMNode(renderer) as Element;
let form = domNode.querySelector("form") as Element;
expect(form).toBeTruthy();
let label = form.querySelector("label")!;
expect(label.innerHTML).toContain("Name :");
let input = form.querySelector("input")!;
expect(input.value).toBe('Your Name');
});
Here, ...
Read now
Unlock full access