Skip to content

Commit 85d04a3

Browse files
committed
Revert "move RoutingContext tests to their own file"
didn't look closely enough, turns out these are RoutingContext tests! This reverts commit 824c816.
1 parent 824c816 commit 85d04a3

File tree

2 files changed

+99
-110
lines changed

2 files changed

+99
-110
lines changed

modules/__tests__/Router-test.js

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,105 @@ describe('Router', function () {
277277

278278
})
279279

280+
describe('RoutingContext', function () {
281+
it('applies custom RoutingContext', function (done) {
282+
const Parent = ({ children }) => <span>parent:{children}</span>
283+
const Child = () => <span>child</span>
284+
285+
class LabelWrapper extends Component {
286+
constructor(props, context) {
287+
super(props, context)
288+
this.createElement = this.createElement.bind(this)
289+
}
290+
291+
createElement(component, props) {
292+
const { label, createElement } = this.props
293+
294+
return (
295+
<span>
296+
{label}-inner:{createElement(component, props)}
297+
</span>
298+
)
299+
}
300+
301+
render() {
302+
const { label, children } = this.props
303+
const child = React.cloneElement(children, {
304+
createElement: this.createElement
305+
})
306+
307+
return (
308+
<span>
309+
{label}-outer:{child}
310+
</span>
311+
)
312+
}
313+
}
314+
315+
LabelWrapper.defaultProps = {
316+
createElement: React.createElement
317+
}
318+
319+
const CustomRoutingContext = props => (
320+
<LabelWrapper label="m1">
321+
<LabelWrapper label="m2">
322+
<RoutingContext {...props} />
323+
</LabelWrapper>
324+
</LabelWrapper>
325+
)
326+
327+
render((
328+
<Router
329+
history={createHistory('/child')}
330+
RoutingContext={CustomRoutingContext}
331+
>
332+
<Route path="/" component={Parent}>
333+
<Route path="child" component={Child} />
334+
</Route>
335+
</Router>
336+
), node, function () {
337+
// Note that the nesting order is inverted for `createElement`, because
338+
// the order of function application is outermost-first.
339+
expect(node.textContent).toBe(
340+
'm1-outer:m2-outer:m2-inner:m1-inner:parent:m2-inner:m1-inner:child'
341+
)
342+
done()
343+
})
344+
})
345+
346+
it('passes router props to custom RoutingContext', function (done) {
347+
const MyComponent = () => <div />
348+
const route = { path: '/', component: MyComponent }
349+
350+
const Wrapper = (
351+
{ routes, components, foo, RoutingContext, children }
352+
) => {
353+
expect(routes).toEqual([ route ])
354+
expect(components).toEqual([ MyComponent ])
355+
expect(foo).toBe('bar')
356+
expect(RoutingContext).toNotExist()
357+
done()
358+
359+
return children
360+
}
361+
const CustomRoutingContext = props => (
362+
<Wrapper {...props}>
363+
<RoutingContext {...props} />
364+
</Wrapper>
365+
)
366+
367+
render((
368+
<Router
369+
history={createHistory('/')}
370+
routes={route}
371+
RoutingContext={CustomRoutingContext}
372+
foo="bar"
373+
/>
374+
), node)
375+
})
376+
377+
})
378+
280379
describe('async components', function () {
281380
let componentSpy, RoutingSpy
282381

modules/__tests__/RoutingContext-test.js

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)