官术网_书友最值得收藏!

Accepting text input

The Git tag for this section is accepting-text-input.

Let's render an HTML text input field onto the page. Add the following test to test/CustomerForm.test.js:

it('renders the first name field as a text box', () => {
render(<CustomerForm />);
const field = form('customer').elements.firstName;
expect(field).not.toBeNull();
expect(field.tagName).toEqual('INPUT');
expect(field.type).toEqual('text');
});
This test makes use of the DOM form API: any form allows access to all of its input elements using the elements indexer. This is a simpler way of accessing form fields than CSS selectors, so I prefer to use it when it's an option.

There are three expectations in this test:

  • For there to be a form element with the name firstName
  • For it to be an input element
  • For it to have a type of text

Let's make them all pass. Update CustomerForm to include a single input field, as shown:

export const CustomerForm = () => (
<form id="customer">
<input
type="text"
name="firstName"
/>

</form>
);
主站蜘蛛池模板: 灵璧县| 东海县| 衡山县| 海晏县| 安顺市| 新平| 中阳县| 新安县| 九龙坡区| 亚东县| 博湖县| 深圳市| 吉林市| 肇源县| 崇义县| 平安县| 霍州市| 健康| 八宿县| 甘泉县| 依兰县| 广水市| 竹溪县| 周宁县| 五峰| 乳源| 新巴尔虎右旗| 博白县| 土默特左旗| 南陵县| 新野县| 宁城县| 玛纳斯县| 苏尼特右旗| 乌拉特后旗| 博客| 黎城县| 阿荣旗| 仁化县| 乐东| 安泽县|