Skip to content

Commit 7f2f93c

Browse files
author
Nicolas Bregenzer
committed
failing test for willTransitionFrom
1 parent f4fe2d7 commit 7f2f93c

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

modules/__tests__/Router-test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,73 @@ describe('Router', function () {
622622
});
623623
});
624624
});
625+
626+
it('should be called when Handler is rendered multiple times on same route', function (done) {
627+
628+
var div = document.createElement('div');
629+
630+
var counter = 0;
631+
632+
var Foo = React.createClass({
633+
statics: {
634+
willTransitionFrom: function (transition, component) {
635+
counter++;
636+
}
637+
},
638+
639+
render: function () {
640+
return <div id="foo">Foo</div>;
641+
}
642+
});
643+
644+
var Bar = React.createClass({
645+
statics: {
646+
willTransitionFrom: function (transition, component) {
647+
counter++;
648+
}
649+
},
650+
651+
render: function () {
652+
return <div id="bar">Bar</div>;
653+
}
654+
});
655+
var routes = (
656+
<Route handler={Nested} path='/'>
657+
<Route name="foo" handler={Foo}/>
658+
<Route name="bar" handler={Bar}/>
659+
</Route>
660+
);
661+
662+
TestLocation.history = [ '/bar' ];
663+
664+
var steps = [];
665+
666+
steps.push(function () {
667+
TestLocation.push('/foo');
668+
});
669+
670+
steps.push(function () {
671+
TestLocation.push('/bar');
672+
});
673+
674+
steps.push(function () {
675+
expect(counter).toEqual(2);
676+
done();
677+
});
678+
679+
Router.run(routes, TestLocation, function (Handler, state) {
680+
681+
// Calling render on the handler twice should be allowed
682+
React.render(<Handler data={{FooBar: 1}}/>, div);
683+
684+
React.render(<Handler data={{FooBar: 1}}/>, div, function () {
685+
setTimeout(function() {
686+
steps.shift()();
687+
}, 1);
688+
});
689+
});
690+
});
691+
625692
});
626693

627694
});

0 commit comments

Comments
 (0)