Skip to content

Commit

Permalink
Modify
Browse files Browse the repository at this point in the history
  • Loading branch information
kuu12 committed Aug 27, 2018
1 parent c9eb539 commit cf50081
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 28 deletions.
9 changes: 8 additions & 1 deletion demo/dynamic.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import React from 'react';
import Routing from '../src';
import Child from './child';
import Log from './log';

const Dynamic = ({ router, path, pathname }) => (
<div id="dynamic">

<Child parentPath={path} path="/child" />
<button
name="dynamic-child"
onClick={() => router.push(`${pathname}/child`)}
>
Show Child
</button>
<Log id="dynamic" data={{ router, path, pathname }} />
</div>
);

Expand Down
2 changes: 1 addition & 1 deletion demo/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';

const Log = ({ id, data }) => {
Log[id] = data;
return <div></div>;
return null;
};

export default Log;
54 changes: 28 additions & 26 deletions test/cache.test.js → test/exclusive-cache.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import Routing from '../src';
import proxy from '../src/proxy';
import { delay } from './util';

const log = (...args) => false && console.log(...args);

let count = 0;

class Aaa extends React.Component {
Expand Down Expand Up @@ -47,11 +49,11 @@ const Root = <ABRoute />;
ReactDOM.render(Root, root);

test('init', () => {
console.log(proxy.router.pathname);
console.log(root.innerHTML);
console.log(JSON.stringify(proxy.router.cache));
console.log(JSON.stringify(proxy.router.registeredRoutes));
console.log('\n');
log(proxy.router.pathname);
log(root.innerHTML);
log(JSON.stringify(proxy.router.cache));
log(JSON.stringify(proxy.router.registeredRoutes));
log('\n');
expect(document.getElementById('aaa'))
.toBeFalsy();
expect(document.getElementById('bbb'))
Expand All @@ -63,11 +65,11 @@ describe('exclusive route', () => {
proxy.router.push('/aaa');
});
test('route rendering', () => {
console.log(proxy.router.pathname);
console.log(root.innerHTML);
console.log(JSON.stringify(proxy.router.cache));
console.log(JSON.stringify(proxy.router.registeredRoutes));
console.log('\n');
log(proxy.router.pathname);
log(root.innerHTML);
log(JSON.stringify(proxy.router.cache));
log(JSON.stringify(proxy.router.registeredRoutes));
log('\n');
expect(document.getElementById('aaa'))
.toBeInstanceOf(HTMLElement);
expect(document.getElementById('bbb'))
Expand All @@ -81,11 +83,11 @@ describe('route change', () => {
await delay(500);
});
test('route rendering', () => {
console.log(proxy.router.pathname);
console.log(root.innerHTML);
console.log(JSON.stringify(proxy.router.cache));
console.log(JSON.stringify(proxy.router.registeredRoutes));
console.log('\n');
log(proxy.router.pathname);
log(root.innerHTML);
log(JSON.stringify(proxy.router.cache));
log(JSON.stringify(proxy.router.registeredRoutes));
log('\n');
const parent = document
.getElementById('aaa')
.parentNode;
Expand All @@ -105,12 +107,12 @@ describe('back', () => {
await delay(500);
});
test('no remount', () => {
console.log(proxy.router.pathname);
console.log(root.innerHTML);
console.log(JSON.stringify(proxy.router.cache));
console.log(JSON.stringify(proxy.router.registeredRoutes));
console.log('\n');
console.log(proxy.router.props.Component);
log(proxy.router.pathname);
log(root.innerHTML);
log(JSON.stringify(proxy.router.cache));
log(JSON.stringify(proxy.router.registeredRoutes));
log('\n');
log(proxy.router.props.Component);
expect(count).toBe(1);
});
});
Expand All @@ -123,11 +125,11 @@ describe('clear cache', () => {
await delay(500);
});
test('remount', () => {
console.log(proxy.router.pathname);
console.log(root.innerHTML);
console.log(JSON.stringify(proxy.router.cache));
console.log(JSON.stringify(proxy.router.registeredRoutes));
console.log('\n');
log(proxy.router.pathname);
log(root.innerHTML);
log(JSON.stringify(proxy.router.cache));
log(JSON.stringify(proxy.router.registeredRoutes));
log('\n');
expect(count).toBe(2);
});
});

0 comments on commit cf50081

Please sign in to comment.