Skip to content

Commit

Permalink
Merge 244a934 into 2dee251
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Mar 8, 2019
2 parents 2dee251 + 244a934 commit 274c580
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 2 deletions.
7 changes: 6 additions & 1 deletion packages/dva/src/index.js
@@ -1,6 +1,10 @@
import React from 'react';
import invariant from 'invariant';
import { createHashHistory } from 'history';
import {
createBrowserHistory,
createMemoryHistory,
createHashHistory,
} from 'history';
import document from 'global/document';
import { Provider, connect, connectAdvanced } from 'react-redux';
import { utils, create, saga } from 'dva-core';
Expand Down Expand Up @@ -118,3 +122,4 @@ export { connect, connectAdvanced };
export { router };
export { saga };
export { routerRedux };
export { createBrowserHistory, createMemoryHistory, createHashHistory };
53 changes: 52 additions & 1 deletion packages/dva/test/index.e2e.js
@@ -1,6 +1,13 @@
import React from 'react';
import { render, fireEvent } from 'react-testing-library';
import dva, { connect } from '../dist/index';
import dva, {
connect,
createMemoryHistory,
router,
routerRedux,
} from '../dist/index';

const { Link, Switch, Route, Router } = router;

test('normal', () => {
const app = dva();
Expand Down Expand Up @@ -56,3 +63,47 @@ test('connect', () => {
fireEvent.click(getByText('add'));
expect(getByTestId('count').innerHTML).toEqual('1');
});

test('navigate', async () => {
const history = createMemoryHistory({
initialEntries: ['/'],
});
const app = dva({
history,
});

function Home() {
return <h1 data-testid="title">You are on Home</h1>;
}
function Users() {
return <h1 data-testid="title">You are on Users</h1>;
}
app.router(({ history }) => {
return (
<Router history={history}>
<>
<Link to="/">Home</Link>
<Link to="/users">Users</Link>
<button
onClick={() => {
app._store.dispatch(routerRedux.push('/'));
}}
>
RouterRedux to Home
</button>
<Switch>
<Route path="/" exact component={Home} />
<Route path="/users" component={Users} />
</Switch>
</>
</Router>
);
});

const { getByTestId, getByText } = render(React.createElement(app.start()));
expect(getByTestId('title').innerHTML).toEqual('You are on Home');
fireEvent.click(getByText('Users'));
expect(getByTestId('title').innerHTML).toEqual('You are on Users');
fireEvent.click(getByText('RouterRedux to Home'));
expect(getByTestId('title').innerHTML).toEqual('You are on Home');
});

0 comments on commit 274c580

Please sign in to comment.