I am trying to figure out how to add testing to my React application. I am using React Testing Library. I am getting this error ReferenceError: regeneratorRuntime is not defined when I try and run the test.
This is what the test file looks like:
import {
render,
screen,
within,
fireEvent,
waitFor
} from '@testing-library/react';
import Providers from '../../context/GlobalContextProviders';
import { BrowserRouter as Router } from 'react-router-dom';
import IngredientsCenter from '../views/IngredientsCenter';
function renderWithProviders(el) {
render(
<Providers>
<Router>{el}</Router>
</Providers>
);
}
test('The ingredients table exists on the screen', async () => {
renderWithProviders(<IngredientsCenter />);
const ingredientsTable = screen.getByRole('ingredients-table');
await waitFor(() => {
expect(ingredientsTable).toBeTruthy();
});
});
Full error with partial relevant stack trace:
regeneratorRuntime is not defined
ReferenceError: regeneratorRuntime is not defined
at C:\...\node_modules\react-table\src\publicUtils.js:169:10
at useAsyncDebounce (C:\...\node_modules\react-table\src\publicUtils.js:169:10)
at GlobalFilter (C:\...\src\components\pieces\IngredientsTable.js:27:19)
And then this is the IngredientsTable file up to just past line 27:
import React, { useState } from 'react';
import {
useTable,
useSortBy,
useGlobalFilter,
useAsyncDebounce
} from 'react-table';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import {
faSortUp,
faSortDown
} from '@fortawesome/pro-duotone-svg-icons';
import {
faCheck,
faEllipsisV
} from '@fortawesome/pro-regular-svg-icons';
import { Scrollbars } from 'rc-scrollbars';
// Define a default UI for filtering
const GlobalFilter = ({
preGlobalFilteredRows,
globalFilter,
setGlobalFilter
}) => {
const count = preGlobalFilteredRows.length;
const [value, setValue] = useState(globalFilter);
const onChange = useAsyncDebounce((value) => {
setGlobalFilter(value || undefined);
}, 200);
I have googled this error and looked it up on here and nothing I have found has helped me. Can someone figure out why my test would be failing with that error?
Looks like you are using webpack because regenerator runtime is already set in Create React App. First install the module:
and in
webpack.config.jsadd this setting to entry:this will make
regeneratorRuntimeavailable globally.