Knowledge check: Automated testing

11. Why is automated testing important? Select all that apply.

  • It offers a faster feedback cycle, bringing faster validation and helping the development team to detect problems or bugs early.
  • It reduces human error.
  • It saves time to development teams.

12. What are some of the best practices when writing your automated tests? Select all that apply

  • They should resemble the way your software is used.
  • Your tests need to be focused on the implementation details of your components.
  • They should be maintainable in the long run.

13. Imagine you have a component that renders both an input tag and a label tag with the exact text Comments:. Inside your test, you have the below piece of code:

const element = screen.getByLabelText(/Comments:/);

What would be the type of element returned by getByLabelText?

  • The document object
  • The label element
  • The input element

14. In a particular test that’s been written for a form component, you encounter the below two lines of code. What kind of data would the handleSubmit variable represent?

const handleSubmit = jest.fn();
render(< FeedbackForm onSubmit={handleSubmit} />);

  • A mock function to track how is called by external code and thus explore the arguments passed in.
  • A copy of the real function that’s used in the parent component that renders the FeedbackForm.
  • A specific function jest provides to handle form submissions

15. What are some of the benefits of Continuous Integration (CI)? Select all that apply.

  • Deliver working software more often.
  • Find bugs earlier and fix them faster.
  • Improved developer productivity.
  • Faster manual integrations.

Module quiz: JSX and Testing

16. What are some of the features of component containment? Select all that apply.

  • A special case of other components.
  • A component that uses the children prop to pass children elements directly as their content.
  • The fact that some components don’t know their children ahead of time.
  • A component that acts as a generic box.

17. What are the props that all components have by default? Select all that apply.

  • children
  • render
  • type

18. What is a React Element? Select all that apply.

  • A JavaScript object that represents the final HTML output.
  • An intermediary representation that describes a component instance.
  • A React Component that represents a simple DOM node, like a button.

Shuffle Q/A 2

19. Assuming you have the below component, what are all the features implemented from component composition with children?

function ConfirmationDialog() {
return (
< Dialog color="blue">
< h1 className="Dialog-title">
Thanks!
< /h1>
< p className="Dialog-message">
We’ll process your order in less than 24 hours.
< /p>
< /Dialog>
);
}

  • Component containment.
  • Component specialization and component containment.
  • Component specialization.

20. What are some of the use cases that the React.cloneElement API allows you to achieve? Select all that apply.

  • Add to children properties.
  • Extend the functionality of children components.
  • Modify children’s properties.

Leave a Reply