我在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
呈现的配置文件组件。