Skip to content

Instantly share code, notes, and snippets.

View adamjarling's full-sized avatar

Adam J. Arling adamjarling

View GitHub Profile
@adamjarling
adamjarling / renderWithRouterMatchExample.js
Created September 24, 2019 20:54
Example of a Testing Library renderWith helper function to include React Router match object in tests
// Component example
// ContentWrapper.jsx
import React from "react";
import Main from "./Main";
import { withRouter } from "react-router-dom";
const ContentWrapper = ({ children, match }) => (
<Main>
<p>Match id: {match.params.id}</p>
{children}
@adamjarling
adamjarling / exampleUsingRouterMatch.js
Last active September 24, 2019 20:36
An example React component which uses React Router's match object to grab a url parameter
import React from "react";
import { withRouter } from "react-router";
import ScreenHeader from "../../components/UI/ScreenHeader";
import Error from "../../components/UI/Error";
import Loading from "../../components/UI/Loading";
import { useQuery } from "@apollo/react-hooks";
import { GET_PROJECT } from "../../components/Project/project.query";
const ScreensProject = ({ match }) => {
const { id } = match.params;
@adamjarling
adamjarling / renderWithRouter.js
Last active July 25, 2023 08:12
Testing Library renderWithRouter helper function
// https://testing-library.com/docs/example-react-router
import React from "react";
import { Router } from "react-router-dom";
import { render } from "@testing-library/react";
import { createMemoryHistory } from "history";
// test utils file
function renderWithRouter(
ui,
{
"@context": [
"http://www.w3.org/ns/anno.jsonld",
"http://iiif.io/api/presentation/3/context.json"
],
"type": "Manifest",
"id": "http://localhost:3333/concern/generic_works/9019s2443/manifest",
"label": "Generic Bunny",
"metadata": [
{