React Jest / React-testing-Library路由更改无法正常工作

时间:2019-02-14 08:56:57

标签: reactjs jestjs react-testing-library

我一直试图记录点击锚标记后的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);

});

1 个答案:

答案 0 :(得分:0)

我删除了root@f11f33d5e5cd:/# cat a.txt spawn openssl pkcs12 -in test.pfx -clcerts -out /etc/freeradius/certs/ecc_radius_cert.pem -nokeys Enter Import Password: MAC verified OK root@f11f33d5e5cd:/# exit 并将其更改为anchors with href s。那解决了这个问题。