-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #567 from travi/alpha
Alpha
- Loading branch information
Showing
9 changed files
with
99 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from 'react'; | ||
import {renderToString} from 'react-dom/server'; | ||
import {RouterContext} from 'react-router'; | ||
|
||
export default function (request, store, renderProps, Root) { | ||
return otherProps => renderToString( | ||
<Root request={request} store={store} {...otherProps}> | ||
<RouterContext {...renderProps} /> | ||
</Root> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import domServer from 'react-dom/server'; | ||
import {RouterContext} from 'react-router'; | ||
import sinon from 'sinon'; | ||
import any from '@travi/any'; | ||
import {assert} from 'chai'; | ||
import defaultRenderFactory from '../../src/default-render-factory'; | ||
|
||
suite('default-render factory', () => { | ||
let sandbox; | ||
const Root = any.simpleObject(); | ||
const store = any.simpleObject(); | ||
|
||
setup(() => { | ||
sandbox = sinon.createSandbox(); | ||
|
||
sandbox.stub(React, 'createElement'); | ||
sandbox.stub(domServer, 'renderToString'); | ||
}); | ||
|
||
teardown(() => sandbox.restore()); | ||
|
||
test('that the router-context is rendered within the provided root component', () => { | ||
const renderProps = any.simpleObject(); | ||
const rootComponent = any.simpleObject(); | ||
const html = any.string(); | ||
const request = any.simpleObject(); | ||
React.createElement.withArgs(RouterContext, renderProps).returns(context); | ||
React.createElement.withArgs(Root, {request, store}, context).returns(rootComponent); | ||
domServer.renderToString.withArgs(rootComponent).returns(html); | ||
|
||
assert.equal(defaultRenderFactory(request, store, renderProps, Root)(), html); | ||
}); | ||
|
||
test('that the additional props are passed to the root component, when provided', () => { | ||
const renderProps = any.simpleObject(); | ||
const rootComponent = any.simpleObject(); | ||
const html = any.string(); | ||
const request = any.simpleObject(); | ||
const otherProps = any.simpleObject(); | ||
React.createElement.withArgs(RouterContext, renderProps).returns(context); | ||
React.createElement.withArgs(Root, {request, store, ...otherProps}, context).returns(rootComponent); | ||
domServer.renderToString.withArgs(rootComponent).returns(html); | ||
|
||
assert.equal(defaultRenderFactory(request, store, renderProps, Root)(otherProps), html); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters