Jest and React Testing Library

Zuhlke Engineering logo

By Vanessa Cassandra / Zuhlke Engineering

Repository

Jest Introduction

	
		
	

Matchers

												
													
												
											

Setup and teardown

												
													
												
											
Scoping

Further readings:

React Testing Library Introduction

Documentation

Rendering Component

	
		
	
			
				
			
		
Query priority

	

		
			
		
	

Queries

  • getBy
  • queryBy
  • findBy
  • getAllBy
  • queryAllBy
  • findAllBy
Types of queries

getBy vs queryBy

			
				
			
		
			
				
			
		

User Action

			
				
			
		
			
				
			
		

userEvent is preferrable.

Differences between fireEvent and userEvent

User Action

		
			
		
	

Testing Async Component

											
												
											
										
										
											
										
									
										
											
										
									
											
												
											
										
											
												
											
										
											
												
											
										

Further readings:

Testing Accessibility

Make your website accessible

Only ~30% of accessibility issues can be found by automated testing

Testing accessibility

  • Testing HTML validity
  • Navigate using a keyboard
  • Navigate using a screen reader

Further readings:

Mocking HTTP Requests and Modules

Mocking ES modules

											
												
											
										

Jest Mock Functions

Mocking HTTP request

Example

Further readings:

Testing Custom Hooks

React hooks can only be called inside a function component. To test a custom hook, one way is to create an example component, and test that component instead.

Example

React Hooks Testing Library

When to use this library?

Examples

Further readings:

Q&A