使用渲染

时间:2017-06-10 15:42:46

标签: reactjs react-router jestjs enzyme react-router-v4

我在React和React-router上有一个简单的应用程序:

import React from "react";
import { Switch, Route } from "react-router-dom";

export const Home = () => (
  <div className="Home">Home</div>
);

export const Profile = () => (
  <div className="Profile">Profile</div>
);

const App = () => (
  <Switch>
    <Route exact path="/" component={Home}/>
    <Route path="/anotherRouteToProfile" component={Profile}/>
  </Switch>
);

export default App;

我想写这样的路由测试

describe('<App />', () => {
  it('on "/profile" render `Profile` container', () => {
    const wrapper = render(
      <MemoryRouter initialEntries={['/profile']}>
        <App/>
      </MemoryRouter>
    );

    expect(
      wrapper.is(Profile)
    ).toBe(true);
  });
});

为什么这个测试通过?在路由/profile上的浏览器中显示空白页面和路由/anotherRouteToProfile呈现的配置文件组件。

enter image description here

0 个答案:

没有答案