小编Boo*_*ter的帖子

React 测试库中的模拟路由器和玩笑

我正在使用 React 测试库和 Jest 编写单元测试,并想检查我的 React 组件是否能够成功导航到下一页。

import { fireEvent, render, screen } from "@testing-library/react";
import React from 'react';
import { Provider } from 'react-redux';
import '@testing-library/jest-dom';
import appStore from '../../src/app/redux/store';
import { MemoryRouter, Route } from 'react-router-dom';
import { createMemoryHistory } from 'history';
import { Router } from 'react-router';

const setup = (initialEntries = []) => {
      let inMemHistory = createMemoryHistory({ initialEntries });
      const utils = render(
        <Router history={inMemHistory}>
          <Provider store={appStore}>
            <Component-1 />
          
          </Provider>
        </Router>
      );
 
      const saveButtonElem = …
Run Code Online (Sandbox Code Playgroud)

mocking reactjs jestjs babel-jest react-testing-library

7
推荐指数
1
解决办法
2万
查看次数