forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouteComponent-test.js
More file actions
69 lines (55 loc) · 1.62 KB
/
RouteComponent-test.js
File metadata and controls
69 lines (55 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import expect from 'expect'
import React, { Component } from 'react'
import { render, unmountComponentAtNode } from 'react-dom'
import createHistory from 'history/lib/createMemoryHistory'
import Router from '../Router'
const { object } = React.PropTypes
describe('a Route Component', function () {
let node
beforeEach(function () {
node = document.createElement('div')
})
afterEach(function () {
unmountComponentAtNode(node)
})
it('injects the right props', function (done) {
class Parent extends Component {
componentDidMount() {
expect(this.props.route).toEqual(parent)
expect(this.props.routes).toEqual([ parent, child ])
}
render() {
return null
}
}
class Child extends Component {
render() {
return null
}
}
const child = { path: 'child', component: Child }
const parent = { path: '/', component: Parent, childRoutes: [ child ] }
render((
<Router history={createHistory('/child')} routes={parent}/>
), node, done)
})
it('receives the right context', function (done) {
class RouteComponent extends Component {
componentDidMount() {
expect(this.context.history).toEqual(this.props.history)
expect(this.context.location).toEqual(this.props.location)
}
render() {
return null
}
}
RouteComponent.contextTypes = {
history: object.isRequired,
location: object.isRequired
}
const route = { path: '/', component: RouteComponent }
render((
<Router history={createHistory('/')} routes={route}/>
), node, done)
})
})