--- id: 5a24c314108439a4d4036178 title: Create a Controlled Input challengeType: 6 isRequired: false videoUrl: '' localeTitle: '' --- ## Description undefined ## Instructions undefined ## Tests
```yml tests: - text: يجب أن يعرض ControlledInput عنصر div يحتوي على input وعلامة p . testString: 'assert(Enzyme.mount(React.createElement(ControlledInput)).find("div").children().find("input").length === 1 && Enzyme.mount(React.createElement(ControlledInput)).find("div").children().find("p").length === 1, "ControlledInput should return a div element which contains an input and a p tag.");' - text: يجب تهيئة حالة ControlledInput مع خاصية input لتعيين سلسلة فارغة. testString: 'assert.strictEqual(Enzyme.mount(React.createElement(ControlledInput)).state("input"), "", "The state of ControlledInput should initialize with an input property set to an empty string.");' - text: يجب أن تؤدي الكتابة في عنصر الإدخال إلى تحديث الحالة وقيمة الإدخال ، ويجب أن يعرض العنصر p هذه الحالة أثناء الكتابة. testString: 'async () => { const waitForIt = (fn) => new Promise((resolve, reject) => setTimeout(() => resolve(fn()), 250)); const mockedComponent = Enzyme.mount(React.createElement(ControlledInput)); const _1 = () => { mockedComponent.setState({ input: "" }); return waitForIt(() => mockedComponent.state("input"))}; const _2 = () => { mockedComponent.find("input").simulate("change", { target: { value: "TestInput" }}); return waitForIt(() => ({ state: mockedComponent.state("input"), text: mockedComponent.find("p").text(), inputVal: mockedComponent.find("input").props().value }))}; const before = await _1(); const after = await _2(); assert(before === "" && after.state === "TestInput" && after.text === "TestInput" && after.inputVal === "TestInput", "Typing in the input element should update the state and the value of the input, and the p element should render this state as you type."); }; ' ```
## Challenge Seed
```jsx class ControlledInput extends React.Component { constructor(props) { super(props); this.state = { input: " }; // change code below this line // change code above this line } // change code below this line // change code above this line render() { return (
{ /* change code below this line */} { /* change code above this line */}

Controlled Input:

{this.state.input}

); } }; ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```