--- id: 5a24c314108439a4d403617d title: Use the Lifecycle Method componentDidMount challengeType: 6 isRequired: false videoUrl: '' localeTitle: '' --- ## Description undefined ## Instructions undefined ## Tests
```yml tests: - text: '' testString: 'assert((() => { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return (mockedComponent.find("div").length === 1 && mockedComponent.find("h1").length === 1); })(), "MyComponent should render a div element which wraps an h1 tag.");' - text: '' testString: 'assert((() => { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return new RegExp("setTimeout(.|\n)+setState(.|\n)+activeUsers").test(String(mockedComponent.instance().componentDidMount)); })(), "Component state should be updated with a timeout function in componentDidMount.");' - text: '' testString: 'async () => { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); const first = () => { mockedComponent.setState({ activeUsers: 1237 }); return mockedComponent.find("h1").text(); }; const second = () => { mockedComponent.setState({ activeUsers: 1000 }); return mockedComponent.find("h1").text(); }; assert(new RegExp("1237").test(first()) && new RegExp("1000").test(second()), "The h1 tag should render the activeUsers value from MyComponent's state."); }; ' ```
## Challenge Seed
```jsx class MyComponent extends React.Component { constructor(props) { super(props); this.state = { activeUsers: null }; } componentDidMount() { setTimeout( () => { this.setState({ activeUsers: 1273 }); }, 2500); } render() { return (

Active Users: { /* change code here */ }

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