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

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>
);
主站蜘蛛池模板: 平果县| 富裕县| 晋城| 东乌珠穆沁旗| 桐柏县| 林甸县| 美姑县| 赣榆县| 昌吉市| 五大连池市| 洛川县| 竹山县| 江安县| 太仓市| 新密市| 巴中市| 黔南| 阜宁县| 平舆县| 建水县| 额尔古纳市| 肇源县| 安溪县| 沙坪坝区| 德格县| 辽阳县| 随州市| 郁南县| 晴隆县| 民乐县| 清水县| 大悟县| 惠水县| 柘城县| 新建县| 汪清县| 介休市| 静宁县| 德安县| 读书| 汾西县|