React
Software-Testing
Simplify Testing with React Testing Library
Scottie Crump, 2021
Inhaltsverzeichnis des Buches
- Simplify Testing with React Testing Library
- Contributors
- About the author
- About the reviewer
- Preface
- Who this book is for?
- What this book covers?
- To get the most out of this book
- Download the example code files
- Download the color images
- Conventions used
- Get in touch
- Reviews
- Chapter 1: Exploring React Testing Library
- Technical requirements
- Introducing the DOM Testing Library
- What is the DOM Testing Library?
- Guiding principles
- Executing test cases with Jest
- Running tests with Jest
- Enhancing Jest assertions with jest-dom
- Adding jest-dom to a project
- Advantages of using jest-dom with Jest
- Testing implementation details
- Problems with implementation detail-focused tests
- Implementation detail-focused test example
- How to move away from implementation detail testing
- Summary
- Questions
- Chapter 2: Working with React Testing Library
- Technical requirements
- Adding React Testing Library to existing projects
- Manual installation
- Automatic installation with create-react-app
- Structuring tests with React Testing Library
- Rendering elements
- Selecting elements in the component DOM output
- Asserting expected behavior
- Testing presentational components
- Creating snapshot tests
- Testing expected properties
- Using the debug method
- Debugging the entire component DOM
- Debugging specific component elements
- Summary
- Questions
- Chapter 3: Testing Complex Components with React Testing Library
- Technical requirements
- Testing user events
- Simulating user actions with fireEvent
- Simulating user actions with user-event
- Testing components that call event handlers in isolation
- Testing components that interact with APIs
- Requesting API data with fetch
- Creating mock API data with MSW
- Testing the DrinkSearch component
- Using MSW in development
- Implementing test-driven development
- Building the Vote component using TDD
- Building a registration form using TDD
- Summary
- Questions
- Chapter 4: Integration Testing and Third-Party Libraries in Your Application
- Technical requirements
- Testing integrated components
- Using integration testing with the Vote component
- Planning test scenarios better suited for isolated testing
- Testing components that use the Context API
- Testing a context consuming Retail component
- Testing the Cart component in isolation
- Testing the Product component in isolation
- Testing the ProductDetail component in isolation
- Testing context errors using error boundaries
- Using integration testing to test view product details
- Testing components that use Redux
- Creating a custom render method for testing Redux consuming components
- Using the test Redux Provider in tests
- Testing components that use GraphQL
- Testing Components that use Material-UI
- Adding an ARIA label to test a Vote component
- Adding a test ID to test a CustomerTable component
- Summary
- Questions
- Chapter 5: Refactoring Legacy Applications with React Testing Library
- Technical requirements
- Using tests to catch regressions when updating dependencies
- Creating the regression test suite
- Upgrading the Material UI dependencies
- Refactoring tests written with Enzyme
- Refactoring tests written with ReactTestUtils
- Refactoring tests to comply with common testing best practices
- Summary
- Questions
- Chapter 6: Implementing Additional Tools and Plugins for Testing
- Technical requirements
- Implementing best practices with Testing Library ESLint plugins
- Installing and configuring eslint-plugin-testing-library
- Installing and configuring eslint-plugin-jest-dom
- Testing accessibility with jest-axe
- Selecting the best queries with Testing Playground
- Selecting queries using the Testing Playground website
- Selecting queries using the Testing Playground Chrome extension
- Increasing our testing productivity with Wallaby.js
- Installing and configuring Wallaby.js
- Writing tests with Interactive Test Output
- Summary
- Questions
- Chapter 7: End-to-End UI Testing with Cypress
- Technical requirements
- Getting started with Cypress
- Enhancing Cypress commands with the Cypress Testing Library
- Cypress-driven development
- Writing Tests using Cypress design patterns
- Creating page objects in Cypress
- Creating custom Commands in Cypress
- Testing APIs with Cypress
- Writing Gherkin-style tests with Cucumber
- Using React Developer Tools with Cypress
- Summary
- Questions
- Answers
- Chapter 1
- Chapter 2
- Chapter 3
- Chapter 4
- Chapter 5
- Chapter 6
- Chapter 7