-
Notifications
You must be signed in to change notification settings - Fork 44
Use hydrate() instead of render() starting from react 16 #30
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import jsdom from 'jsdom'; | ||
import { assert } from 'chai'; | ||
import sinon from 'sinon'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
import ExampleReactComponent from './components/ExampleReactComponent'; | ||
import { renderReact } from '..'; | ||
|
@@ -20,7 +22,7 @@ describe('renderReact', () => { | |
assert.match(result, /Hello Desmond/); | ||
}); | ||
|
||
it('calls hypernova.client', (done) => { | ||
it('calls hypernova.client (hydrate method)', (done) => { | ||
jsdom.env(result, (err, window) => { | ||
if (err) { | ||
done(err); | ||
|
@@ -30,9 +32,44 @@ describe('renderReact', () => { | |
global.window = window; | ||
global.document = window.document; | ||
|
||
const hydrateMethod = sinon.spy(ReactDOM, 'hydrate'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will this work when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ljharb yes, this test runs in the hypernova-react package which (in this PR) depends on React ^16 and therefore always has the hydrate method available. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hypernova-react doesn't depend on v16, it devDepends on it, and peerDepends on 0.14 or 0.15 or 16 - if we wanted to test this repo on 0.14 or 0.15 (which we should, if we're not already), this test would fail. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. how will we switch the react version to in our test cases? Shouldn't we use v16 and mock v15/v0.14 behaviour, which I'm doing on line 59 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine for this PR :-) when we actually add tests on all the React versions, we wouldn't want to mock things out - mocks make tests more brittle. |
||
|
||
// Calling it again for the client. | ||
renderReact('ExampleReactComponent', ExampleReactComponent); | ||
|
||
assert(hydrateMethod.calledOnce); | ||
|
||
delete global.window; | ||
delete global.document; | ||
|
||
hydrateMethod.restore(); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('calls hypernova.client (render method)', (done) => { | ||
jsdom.env(result, (err, window) => { | ||
if (err) { | ||
done(err); | ||
return; | ||
} | ||
|
||
const sandbox = sinon.createSandbox(); | ||
sandbox.stub(ReactDOM, 'hydrate').value(undefined); | ||
|
||
const renderMethod = sinon.spy(ReactDOM, 'render'); | ||
|
||
global.window = window; | ||
global.document = window.document; | ||
|
||
// Calling it again for the client. | ||
renderReact('ExampleReactComponent', ExampleReactComponent); | ||
|
||
assert(renderMethod.calledOnce); | ||
|
||
sandbox.restore(); | ||
|
||
delete global.window; | ||
delete global.document; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb like this? when I test this it always installs v16
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep! that's fine, it will always install the latest, but it will be valid to install older versions.