Skip to content

Commit 2333325

Browse files
committed
Merge pull request #632 from nicib83/master
failing test for willTransitionFrom
2 parents 2f910f7 + dcc4680 commit 2333325

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

modules/__tests__/Router-test.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,73 @@ describe('Router', function () {
736736
});
737737
});
738738
});
739+
740+
it('should be called when Handler is rendered multiple times on same route', function (done) {
741+
742+
var div = document.createElement('div');
743+
744+
var counter = 0;
745+
746+
var Foo = React.createClass({
747+
statics: {
748+
willTransitionFrom: function (transition, component) {
749+
counter++;
750+
}
751+
},
752+
753+
render: function () {
754+
return <div id="foo">Foo</div>;
755+
}
756+
});
757+
758+
var Bar = React.createClass({
759+
statics: {
760+
willTransitionFrom: function (transition, component) {
761+
counter++;
762+
}
763+
},
764+
765+
render: function () {
766+
return <div id="bar">Bar</div>;
767+
}
768+
});
769+
var routes = (
770+
<Route handler={Nested} path='/'>
771+
<Route name="foo" handler={Foo}/>
772+
<Route name="bar" handler={Bar}/>
773+
</Route>
774+
);
775+
776+
TestLocation.history = [ '/bar' ];
777+
778+
var steps = [];
779+
780+
steps.push(function () {
781+
TestLocation.push('/foo');
782+
});
783+
784+
steps.push(function () {
785+
TestLocation.push('/bar');
786+
});
787+
788+
steps.push(function () {
789+
expect(counter).toEqual(2);
790+
done();
791+
});
792+
793+
Router.run(routes, TestLocation, function (Handler, state) {
794+
795+
// Calling render on the handler twice should be allowed
796+
React.render(<Handler data={{FooBar: 1}}/>, div);
797+
798+
React.render(<Handler data={{FooBar: 1}}/>, div, function () {
799+
setTimeout(function() {
800+
steps.shift()();
801+
}, 1);
802+
});
803+
});
804+
});
805+
739806
});
740807

741808
});

modules/utils/createRouter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ function createRouter(options) {
169169

170170
function updateState() {
171171
state = nextState;
172-
nextState = {};
173172
}
174173

175174
if (typeof location === 'string') {
@@ -400,6 +399,7 @@ function createRouter(options) {
400399
if (error || transition.isAborted)
401400
return dispatchHandler.call(router, error, transition);
402401

402+
nextState = {};
403403
nextState.path = path;
404404
nextState.action = action;
405405
nextState.pathname = pathname;

0 commit comments

Comments
 (0)