Skip to content

Commit d88a051

Browse files
committed
added index route tests
1 parent 25ad858 commit d88a051

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*eslint-env mocha */
2+
/*eslint react/prop-types: 0*/
3+
import expect from 'expect'
4+
import React from 'react'
5+
import createHistory from 'history/lib/createMemoryHistory'
6+
import IndexRoute from '../IndexRoute'
7+
import Router from '../Router'
8+
import Route from '../Route'
9+
10+
describe('an <IndexRoute/>', function () {
11+
12+
var node
13+
beforeEach(function () {
14+
node = document.createElement('div')
15+
})
16+
17+
afterEach(function () {
18+
React.unmountComponentAtNode(node)
19+
})
20+
21+
var Parent = React.createClass({
22+
render () {
23+
return <div>parent {this.props.children}</div>
24+
}
25+
})
26+
27+
var Child = React.createClass({
28+
render () {
29+
return <div>child </div>
30+
}
31+
})
32+
33+
it('renders when its parent’s url matches exactly', function (done) {
34+
React.render((
35+
<Router history={createHistory('/')}>
36+
<Route path="/" component={Parent}>
37+
<IndexRoute component={Child}/>
38+
</Route>
39+
</Router>
40+
), node, function () {
41+
expect(node.textContent.trim()).toEqual('parent child')
42+
done()
43+
})
44+
})
45+
46+
describe('nested deeply in the route hierarchy', function () {
47+
it('renders when its parent’s url matches exactly', function (done) {
48+
React.render((
49+
<Router history={createHistory('/test')}>
50+
<Route path="/" component={Parent}>
51+
<IndexRoute component={Child}/>
52+
<Route path="/test" component={Parent}>
53+
<IndexRoute component={Child}/>
54+
</Route>
55+
</Route>
56+
</Router>
57+
), node, function () {
58+
expect(node.textContent.trim()).toEqual('parent parent child')
59+
done()
60+
})
61+
})
62+
})
63+
})

0 commit comments

Comments
 (0)