Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
We need to mock reac-markdown and react-leaflet since jest does not
fully support ESM syntax yet. See
remarkjs/react-markdown#635 (comment).
  • Loading branch information
cmil committed Sep 28, 2022
1 parent e33dc21 commit 7a2a4d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"locations": "ts-node -O '{\"isolatedModules\":false,\"module\":\"CommonJS\"}' fetch-locations.ts",
"start": "yarn compile && yarn csv && yarn json && craco start",
"build": "yarn compile && yarn csv && yarn json && yarn beacon && craco build",
"test": "yarn compile && yarn csv && yarn json && react-scripts test",
"test": "yarn compile && yarn csv && yarn json && craco test",
"extract": "lingui extract",
"compile": "lingui compile",
"eject": "react-scripts eject"
Expand Down
11 changes: 7 additions & 4 deletions src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import React from 'react';
import { render } from '@testing-library/react';
import { render, screen } from '@testing-library/react';
import { I18nProvider } from '@lingui/react';
import {HelmetProvider} from 'react-helmet-async';
import i18n from './i18n';
import App from './App';

test('renders heading', () => {
const { getByText } = render(
render(
<I18nProvider i18n={i18n}>
<App />
<HelmetProvider>
<App />
</HelmetProvider>
</I18nProvider>
);
const element = getByText(/^about$/i);
const element = screen.getByText(/^about$/i);
expect(element).toBeInTheDocument();
});
11 changes: 11 additions & 0 deletions src/__mocks__/react-leaflet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export function MapContainer({ children }){
return <>{children}</>;
}

export function TileLayer({ children }){
return <>{children}</>;
}

export function Marker({ children }){
return <>{children}</>;
}
5 changes: 5 additions & 0 deletions src/__mocks__/react-markdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function ReactMarkdown({ children }){
return <>{children}</>;
}

export default ReactMarkdown;

0 comments on commit 7a2a4d3

Please sign in to comment.