-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support nested routes, and a base prop to start from if necessary #100
base: main
Are you sure you want to change the base?
Changes from 17 commits
d43d920
c1931cb
257a761
a8fab3a
839775c
d7e5755
bf1dd22
9e4a87b
3f36e28
abb475e
218b127
a6114af
5ac00bd
132b302
dcdd3f4
07f14d7
6b2332f
a26343a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,195 @@ describe('dom', () => { | |
expect(A.prototype.componentWillUnmount).to.have.been.calledOnce; | ||
}); | ||
|
||
it('should support nested routers with default', () => { | ||
class X { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(X.prototype, 'componentWillMount'); | ||
sinon.spy(X.prototype, 'componentWillUnmount'); | ||
class Y { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(Y.prototype, 'componentWillMount'); | ||
sinon.spy(Y.prototype, 'componentWillUnmount'); | ||
mount( | ||
<Router base="/app"> | ||
<X path="/x" /> | ||
<Router default> | ||
<Y path="/y"/> | ||
</Router> | ||
</Router> | ||
); | ||
expect(X.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
route('/app/x'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
route('/app/y'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
}); | ||
|
||
it('should support nested routers with path', () => { | ||
class X { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(X.prototype, 'componentWillMount'); | ||
sinon.spy(X.prototype, 'componentWillUnmount'); | ||
class Y { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(Y.prototype, 'componentWillMount'); | ||
sinon.spy(Y.prototype, 'componentWillUnmount'); | ||
mount( | ||
<Router base='/baz'> | ||
<X path="/j" /> | ||
<Router path="/box/:bar*"> | ||
<Y path="/k"/> | ||
</Router> | ||
</Router> | ||
); | ||
expect(X.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
route('/baz/j'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
route('/baz/box/k'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
}); | ||
|
||
it('should support deeply nested routers', () => { | ||
class X { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(X.prototype, 'componentWillMount'); | ||
sinon.spy(X.prototype, 'componentWillUnmount'); | ||
class Y { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(Y.prototype, 'componentWillMount'); | ||
sinon.spy(Y.prototype, 'componentWillUnmount'); | ||
mount( | ||
<Router base='/baz'> | ||
<X path="/j" /> | ||
<z path="/box/:bar*"> | ||
<Router path="/box"> | ||
<Y path="/k"/> | ||
</Router> | ||
</z> | ||
</Router> | ||
); | ||
expect(X.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
route('/baz/j'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
route('/baz/box/k'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
}); | ||
|
||
it('should support nested routers with Match', () => { | ||
class X { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(X.prototype, 'componentWillMount'); | ||
sinon.spy(X.prototype, 'componentWillUnmount'); | ||
class Y { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(Y.prototype, 'componentWillMount'); | ||
sinon.spy(Y.prototype, 'componentWillUnmount'); | ||
mount( | ||
<Router base='/ccc'> | ||
<X path="/jjj" /> | ||
<Match path="/xxx/:bar*"> | ||
<Router> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While the other nested router tests pass, the Match here cannot render the child as it is a vNode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm. yeah we might need to do type detection in Match. I realize now we sortof have two matches, so it might be good to merge them. Need to think on this for sure, because I like the options your Match gives us. |
||
<Y path="/kkk"/> | ||
</Router> | ||
</Match> | ||
</Router> | ||
); | ||
expect(X.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
route('/ccc/jjj'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
route('/ccc/xxx/kkk'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
}); | ||
|
||
it('should support nested router reset via base attr', () => { | ||
class X { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(X.prototype, 'componentWillMount'); | ||
sinon.spy(X.prototype, 'componentWillUnmount'); | ||
class Y { | ||
componentWillMount() {} | ||
componentWillUnmount() {} | ||
render(){ return <div />; } | ||
} | ||
sinon.spy(Y.prototype, 'componentWillMount'); | ||
sinon.spy(Y.prototype, 'componentWillUnmount'); | ||
mount( | ||
<Router base='/baz'> | ||
<X path="/j" /> | ||
<Router path="/:bar*" base="/baz/foo"> | ||
<Y path="/k"/> | ||
</Router> | ||
</Router> | ||
); | ||
expect(X.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
route('/baz/j'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillMount).not.to.have.been.called; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
route('/baz/foo/k'); | ||
expect(X.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(X.prototype.componentWillUnmount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillMount).to.have.been.calledOnce; | ||
expect(Y.prototype.componentWillUnmount).not.to.have.been.called; | ||
}); | ||
|
||
it('should support re-routing', done => { | ||
class A { | ||
componentWillMount() { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need to move this into the
if
block on L156?