All Projects → LauraBeatris → react-router-testing-utils

LauraBeatris / react-router-testing-utils

Licence: MIT license
A collection of utilities to test React Router with React Testing Library (Work in progress 🚧)

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-router-testing-utils

test-real-styles
(test-)framework agnostic utilities to test real styling of (virtual) dom elements
Stars: ✭ 37 (+8.82%)
Mutual labels:  testing-tools, testing-library
mocat
🐈 Mocat is a mocking toolbar that allows you to interactively develop and test network requests.
Stars: ✭ 27 (-20.59%)
Mutual labels:  testing-tools, testing-library
api-test
🌿 A simple bash script to test JSON API from terminal in a structured and organized way.
Stars: ✭ 53 (+55.88%)
Mutual labels:  testing-tools, testing-library
scalatest-junit-runner
JUnit 5 runner for Scalatest
Stars: ✭ 30 (-11.76%)
Mutual labels:  testing-tools, testing-library
toster
DSL framework for testing Android apps
Stars: ✭ 31 (-8.82%)
Mutual labels:  testing-tools, testing-library
React-Netflix-Clone
A Fully Responsive clone of Netflix website built using React.JS as a Front-end & Firebase as a Back-end.
Stars: ✭ 91 (+167.65%)
Mutual labels:  react-router
cra-template-quickstart-redux
Opinionated quickstart Create React App template with Redux, React Testing Library and custom eslint configuration
Stars: ✭ 66 (+94.12%)
Mutual labels:  testing-library
ts-react-boilerplate
A very opinionated (React/TypeScript/Redux/etc) frontend boilerplate
Stars: ✭ 43 (+26.47%)
Mutual labels:  react-router
react-boilerplate
React 18, React-Router, Typescript, Vite, Babel 7, React-Testing-Library, Vitest
Stars: ✭ 27 (-20.59%)
Mutual labels:  react-router
pymongo inmemory
A mongo mocking library with an ephemeral MongoDB running in memory.
Stars: ✭ 25 (-26.47%)
Mutual labels:  testing-tools
network image mock
Mock response for Image.network to help Flutter widget tests pass.
Stars: ✭ 22 (-35.29%)
Mutual labels:  testing-tools
FactoryOrchestrator
A cross-platform system service which provides a simple way to run and manage factory line validation, developer inner-loop, diagnostics, and fault analysis workflows.
Stars: ✭ 36 (+5.88%)
Mutual labels:  testing-library
vividus-starter
VIVIDUS-based test project template
Stars: ✭ 43 (+26.47%)
Mutual labels:  testing-tools
hot-redux-chassis
Modern React/Redux/RxJS application using all the latest and greatest stuff from the community 🔥
Stars: ✭ 20 (-41.18%)
Mutual labels:  react-router
rgxp
Regular Expression Collection (ReactJS, Redux, React Router, Recompose, NodeJS, Express)
Stars: ✭ 62 (+82.35%)
Mutual labels:  react-router
blackhole
Blackhole is an MTA written on top of asyncio, utilising async and await statements that dumps all mail it receives to /dev/null.
Stars: ✭ 61 (+79.41%)
Mutual labels:  testing-tools
SHAFT ENGINE
SHAFT is an MIT licensed test automation engine. Powered by best-in-class frameworks like Selenium WebDriver, Appium & RestAssured it provides a wizard-like syntax to increase productivity, and built-in wrappers to eliminate boilerplate code and to ensure your tests are extra stable and your results are extra reliable.
Stars: ✭ 170 (+400%)
Mutual labels:  testing-tools
awesome-cypress
🎉 A curated list of awesome things related to Cypress
Stars: ✭ 274 (+705.88%)
Mutual labels:  testing-tools
whatsapp-clone-react
Build a WhatsApp Clone with React JS and FireBase.
Stars: ✭ 38 (+11.76%)
Mutual labels:  react-router
realestate
A simple real estate app build with MEAN( Angular, Node and mongoDb ) and MERN( React, Node and mongoDb )
Stars: ✭ 33 (-2.94%)
Mutual labels:  react-router

react-router-testing-utils

logo

A collection of utilities to test React Router with React Testing Library


Build Status version MIT License All Contributors

Watch on GitHub Star on GitHub Tweet

Table of Contents

Installation

This module should be installed as one of your project's devDependencies:

With NPM

npm install --save-dev react-router-testing-utils

or

With yarn package manager

yarn add --dev react-router-testing-utils

Setup

Import react-router-testing-utils/extend-expect in your tests setup file, in order to extend Jest expectations:

// In your own jest-setup.js (or any other name)
import 'react-router-testing-utils/extend-expect'

// In jest.config.js add (if you haven't already)
setupFilesAfterEnv: ['<rootDir>/jest-setup.js']

With TypeScript

If you're using TypeScript, make sure your setup file is a .ts and not a .js to include the necessary types.

You will also need to include your setup file in your tsconfig.json if you haven't already:

  // In tsconfig.json
  "include": [
    ...
    "./jest-setup.ts"
  ],

Render in Router

This allows you to render a given component in a Router for un-browser environments

renderInRouter(ExampleAppRoutes, {
   initialEntries: ['/about']
})

expect(screen.getByTestId('example-about-page')).toBeVisible()

Custom matchers

toHaveQueryParam

This allows you to check if a location search has a certain query param value.

A query param is contained in a location search if all the following conditions are met:

  • It's name is contained in the location search
  • It's value is contained in the location search
  • It's given type corresponds to it's decoded value

In order to encode/decode query params, it's necessary to provide the param type from ParamTypes exported module

Examples

import { ParamTypes } from 'react-router-testing-utils'

const { history } = renderInRouter(ExampleAppRoutes, {
   shouldCheckHistory: true,
})

expect(history?.location.search).toHaveQueryParam({
   name: 'filter-object',
   type: ParamTypes.ObjectParam,
   value: { foo: 'foo' }
})

LICENSE

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].