forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRouter-test.js
More file actions
107 lines (94 loc) · 2.68 KB
/
Router-test.js
File metadata and controls
107 lines (94 loc) · 2.68 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import expect from 'expect';
import React from 'react';
import { createLocation } from 'history';
import Router from '../Router';
import Route from '../Route';
describe('Router', function () {
var node;
beforeEach(function () {
node = document.createElement('div');
});
afterEach(function () {
React.unmountComponentAtNode(node);
});
var Parent = React.createClass({
render() {
return <div>parent{this.props.children}</div>;
}
});
var Child = React.createClass({
render() {
return <div>child</div>;
}
});
it('renders routes', function (done) {
React.render((
<Router location={createLocation('/')}>
<Route path="/" component={Parent} />
</Router>
), node, function () {
expect(node.textContent.trim()).toEqual('parent');
done();
});
});
it('renders child routes when the parent does not have a path', function (done) {
React.render((
<Router location={createLocation('/')}>
<Route component={Parent}>
<Route component={Parent}>
<Route path="/" component={Child} />
</Route>
</Route>
</Router>
), node, function () {
expect(node.textContent.trim()).toEqual('parentparentchild');
done();
});
});
it('renders nested children correctly', function (done) {
React.render((
<Router location={createLocation('/hello')}>
<Route component={Parent}>
<Route path="hello" component={Child} />
</Route>
</Router>
), node, function () {
expect(node.textContent.trim()).toMatch(/parent/);
expect(node.textContent.trim()).toMatch(/child/);
done();
});
});
it('renders the child\'s component when it has no component', function (done) {
React.render((
<Router location={createLocation('/hello')}>
<Route>
<Route path="hello" component={Child} />
</Route>
</Router>
), node, function () {
expect(node.textContent.trim()).toMatch(/child/);
done();
});
});
it('renders with a custom `createElement` prop', function(done) {
var Wrapper = React.createClass({
render() {
var { Component } = this.props;
return <Component fromWrapper="wrapped" />
}
});
var Component = React.createClass({
render() {
return <div>{this.props.fromWrapper}</div>;
}
});
React.render((
<Router location={createLocation('/')} createElement={Component => <Wrapper Component={Component} />}>
<Route path="/" component={Component}/>
</Router>
), node, function () {
expect(node.textContent.trim()).toEqual('wrapped');
done();
});
});
});