Я пытался записать изменения URL при клике на тег привязки.Хотя это работает на реальной странице, это не так, когда я пишу тесты в Jest.
Вот код:
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);
});