Skip to content

Commit f1e500a

Browse files
committed
Fixup and extend nested contextual router tests.
1 parent f1f07ee commit f1e500a

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

tests/server.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,18 @@ describe('react-router-component (on server)', function() {
129129
var Level2 = React.createClass({
130130

131131
render: function() {
132+
var thisSlug = this.props.slug;
132133
return Router.Locations({className: 'L2', contextual: true},
133134
Router.Location({
134135
path: '/',
135136
handler: function(props) {
136-
return Router.Link({href: '/hello'});
137+
return Router.Link({href: '/hello', 'data-slug': thisSlug});
137138
}
138139
}),
139140
Router.Location({
140141
path: '/:slug',
141142
handler: function(props) {
142-
return Router.Link({global: true, href: '/hi'});
143+
return Router.Link({global: true, href: '/hi', 'data-slug': props.slug});
143144
}
144145
})
145146
)
@@ -149,11 +150,12 @@ describe('react-router-component (on server)', function() {
149150
var Level1 = React.createClass({
150151

151152
render: function() {
153+
var thisSlug = this.props.slug;
152154
return Router.Locations({className: 'L1', contextual: true},
153155
Router.Location({
154156
path: '/',
155157
handler: function(props) {
156-
return Router.Link({href: '/l2'});
158+
return Router.Link({href: '/l2', 'data-slug': thisSlug});
157159
}
158160
}),
159161
Router.Location({
@@ -180,22 +182,33 @@ describe('react-router-component (on server)', function() {
180182
var markup = React.renderComponentToString(App({path: '/l1/nice'}));
181183
assert(markup.match(/class="App"/));
182184
assert(markup.match(/class="L1"/));
183-
assert(markup.match(/href="/l1/nice/l2"/));
185+
assert(markup.match(/href="\/l1\/nice\/l2"/));
186+
assert(markup.match(/data-slug="nice"/));
187+
});
188+
189+
it ('renders Link component with href scoped to its prefix - trailing slash', function() {
190+
var markup = React.renderComponentToString(App({path: '/l1/nice/'}));
191+
assert(markup.match(/class="App"/));
192+
assert(markup.match(/class="L1"/));
193+
assert(markup.match(/href="\/l1\/nice\/l2"/));
194+
assert(markup.match(/data-slug="nice"/));
184195
});
185196

186197
it ('renders nested Link component with href scoped to its prefix', function() {
187198
var markup = React.renderComponentToString(App({path: '/l1/nice/l2'}));
188199
assert(markup.match(/class="App"/));
189200
assert(markup.match(/class="L1"/));
190201
assert(markup.match(/class="L2"/));
191-
assert(markup.match(/href="/l1/nice/l2/hello"/));
202+
assert(markup.match(/href="\/l1\/nice\/l2\/hello"/));
203+
assert(markup.match(/data-slug="l2"/));
192204
});
193205

194206
it ('renders global Link component with correct href (not scoped to a router)', function() {
195207
var markup = React.renderComponentToString(App({path: '/l1/nice/l2/foo'}));
196208
assert(markup.match(/class="App"/));
197209
assert(markup.match(/class="L2"/));
198-
assert(markup.match(/href="/hi"/));
210+
assert(markup.match(/href="\/hi"/));
211+
assert(markup.match(/data-slug="foo"/));
199212
});
200213

201214
});

0 commit comments

Comments
 (0)