I have been trying to record URL changes on click of anchor tag. While this works on the actual page, it doesn't when I write tests in Jest.
Here's the code:
import { renderApp } from "<src>/tests/util";
import { fireEvent, wait } from "react-testing-library";
import {
getLocationAPath,
getLocationBPath,
getLocationCPath
} from "<src>/paths";
let getByDataQa;
let history;
beforeEach(() => {
({ getByDataQa, history } = renderApp(getLocationAPath(), {}));
});
test("Validate if routes work", async () => {
let routePath;
fireEvent.click(getByDataQa("Container.locB"));
//await wait();
routePath = getLocationBPath();
expect(history.location.pathname).toEqual(routePath);
fireEvent.click(getByDataQa("Container.locC"));
routePath = getLocationCPath();
console.log(history.location.pathname);
expect(history.location.pathname).toEqual(routePath);
});
renderApp?