freeCodeCamp/curriculum/challenges/arabic/03-front-end-libraries/react/use-the-lifecycle-method-co...

1.3 KiB

id title challengeType isRequired videoUrl localeTitle
5a24c314108439a4d403617c Use the Lifecycle Method componentWillMount 6 false

Description

undefined

Instructions

undefined

Tests

tests:
  - text: ''
    testString: 'assert((function() { const mockedComponent = Enzyme.mount(React.createElement(MyComponent)); return mockedComponent.find("div").length === 1; })(), "<code>MyComponent</code> should render a <code>div</code> element.");'
  - text: ''
    testString: 'assert((function() { const lifecycle = React.createElement(MyComponent).type.prototype.componentWillMount.toString().replace(/ /g,""); return lifecycle.includes("console.log("); })(), "<code>console.log</code> should be called in <code>componentWillMount</code>.");'

Challenge Seed

class MyComponent extends React.Component {
  constructor(props) {
    super(props);
  }
  componentWillMount() {
    // change code below this line

    // change code above this line
  }
  render() {
    return <div />
  }
};

After Test

console.info('after the test');

Solution

// solution required