How to set up the Test Environment

Developed with
QA
play-arrow
How to set up the Test Environment
Overview
DifficultyBeginner
Duration44m
Students129
Ratings
3.2/5
starstarstarstar-halfstar-border

Description

This module looks at testing in React. You’ll learn how to set up a test environment, Jest, and other useful tools to test your React App.   

Learning Objectives 

The objectives of this module are to provide you with an understanding of: 

  • How to set up the test environment  
  • Jest  
  • Snapshot testing  
  • How to test with Props  
  • How to mock components for testing  
  • Mock functions  
  • How to test components asynchronously  
  • How to test components with routing  
  • How to test custom hooks 

Intended Audience  

This learning path is aimed at all who wish to learn how to use the ReactJS framework.  

Prerequisites

It is essential you understand the face of contemporary web development to attend this course. We insist upon JavaScript experience, along with good HTML and CSS skills. 

Feedback 

We welcome all feedback and suggestions - please contact us at qa.elearningadmin@qa.com to let us know what you think. 

Transcript

- [Instructor] If you've started a project using create-react-app. You've already got everything you need to start testing your application setup. It comes with jest baked into the setup and a sample test spec for the app component. If you examine the package.json file, the command test is already in the script section on line 15. And you can see that testing library jest-dom, react and user-event have been added as dependencies, on line six to eight. This is the package.json file from a new app scaffolded with create-react-app. The command npm test can be used on the console to run the tests. And these will hot load as you make changes to them or the files they test. We press A to run all of the tests, and you can see that the default test provided for the app component passes. Tests should have .test. in their file name as a convention, to help identify them. But create-react-app is to configured, to look for tests in any file and to use them when running tests. For this reason, the test files don't need to be saved in the same folder as the item they were testing. In fact it could get mighty confusing, if you don't follow the convention. We've moved the app.test.js file into a folder we've called __testing __. Those underscores help to visually identify it as non-production code folder. And there's another convention. If you haven't used create-react-app. The react and jest documentation explain how to add testing to your project.

Lectures

Introduction to Testing React with Jest - Jest - The What and How of Testing in React - Snapshot Testing - Testing Components with Props - Mocking Components for Testing - Testing State Events Interactions - Mocking Functions - Testing Components Asynchronously - Testing Components with Routing - Testing Custom Hooks  

About the Author
Students4289
Labs8
Courses29
Learning paths6

Ed is an Outstanding Trainer in Software Development, with a passion for technology and its uses and holding more than 10 years’ experience.

Previous roles have included being a Delivery Manager, Trainer, ICT teacher, and Head of Department. Ed continues to develop existing and new courses, primarily in web design using: PHP, JavaScript, HTML, CSS, SQL, and OOP (Java), Programming Foundations (Python), and DevOps (Git, CI/CD, etc). Ed describes himself as practically minded, a quick learner, and a problem solver who pays great attention to detail. 

Ed’s specialist area is training in Emerging Technologies, within Web Development. Ed mainly delivers courses in JavaScript covering vanilla JS, ES2015+, TypeScript, Angular, and React (the latter is authored by Ed) and has delivered on behalf of Google for PWAs. Ed has also developed a new suite of PHP courses and has extensive experience with HTML/CSS and MySQL. 

Ed is responsible for delivering QA’s Programming Foundations course using the Eclipse IDE. His skillset extends into the DevOps sphere, where he is able to deliver courses based around Agile/Scrum practices, version control, and CI/CD.

Covered Topics