|
1 | 1 | require('./helper');
|
| 2 | +var Promise = require('es6-promise').Promise; |
2 | 3 | var Router = require('../modules/Router');
|
3 | 4 | var RouteComponent = require('../modules/components/Route');
|
4 | 5 |
|
@@ -125,6 +126,45 @@ describe('a Router with custom props', function() {
|
125 | 126 | });
|
126 | 127 | });
|
127 | 128 |
|
| 129 | +describe('a Router that renders on the server', function() { |
| 130 | + it('works with async willTransitionTo()', function(done) { |
| 131 | + var dataStore = 'goodbye'; |
| 132 | + var Layout = React.createClass({ |
| 133 | + render: function() { |
| 134 | + return React.DOM.article(null, this.props.activeRoute); |
| 135 | + } |
| 136 | + }); |
| 137 | + var AsyncApp = React.createClass({ |
| 138 | + displayName: 'AsyncApp', |
| 139 | + statics: { |
| 140 | + willTransitionTo: function() { |
| 141 | + return new Promise(function(resolve) { |
| 142 | + setTimeout(function() { |
| 143 | + dataStore = 'hello'; |
| 144 | + resolve(); |
| 145 | + }, 0); |
| 146 | + }); |
| 147 | + } |
| 148 | + }, |
| 149 | + render: function() { |
| 150 | + return React.DOM.div(null, dataStore); |
| 151 | + } |
| 152 | + }); |
| 153 | + |
| 154 | + var router = Router( |
| 155 | + RouteComponent({ path: '/', handler: Layout}, |
| 156 | + RouteComponent({ path: '/a', handler: AsyncApp })) |
| 157 | + ); |
| 158 | + |
| 159 | + router.renderComponentToString('/a').then(function(result) { |
| 160 | + expect(result.indexOf('div') > -1).toBe(true); |
| 161 | + expect(result.indexOf('hello') > -1).toBe(true); |
| 162 | + |
| 163 | + done(); |
| 164 | + }); |
| 165 | + }); |
| 166 | +}); |
| 167 | + |
128 | 168 | function lastItem(array) {
|
129 | 169 | return array[array.length - 1];
|
130 | 170 | }
|
0 commit comments