-
Notifications
You must be signed in to change notification settings - Fork 46.9k
/
ReactServerRenderingBrowser-test.js
67 lines (61 loc) · 1.98 KB
/
ReactServerRenderingBrowser-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails react-core
* @jest-environment node
*/
'use strict';
let React;
let ReactDOMServer;
let ReactDOMServerBrowser;
describe('ReactServerRenderingBrowser', () => {
beforeEach(() => {
jest.resetModules();
React = require('react');
ReactDOMServer = require('react-dom/server');
// For extra isolation between what would be two bundles on npm
jest.resetModuleRegistry();
ReactDOMServerBrowser = require('react-dom/server.browser');
});
it('provides the same top-level API as react-dom/server', () => {
expect(Object.keys(ReactDOMServerBrowser)).toEqual(
Object.keys(ReactDOMServer),
);
});
it('returns the same results as react-dom/server', () => {
class Nice extends React.Component {
render() {
return <h2>I am feeling very good today, thanks, how are you?</h2>;
}
}
function Greeting() {
return (
<div>
<h1>How are you?</h1>
<Nice />
</div>
);
}
expect(ReactDOMServerBrowser.renderToString(<Greeting />)).toEqual(
ReactDOMServer.renderToString(<Greeting />),
);
expect(ReactDOMServerBrowser.renderToStaticMarkup(<Greeting />)).toEqual(
ReactDOMServer.renderToStaticMarkup(<Greeting />),
);
});
it('throws meaningfully for server-only APIs', () => {
expect(() => ReactDOMServerBrowser.renderToNodeStream(<div />)).toThrow(
'ReactDOMServer.renderToNodeStream(): The streaming API is not available ' +
'in the browser. Use ReactDOMServer.renderToString() instead.',
);
expect(() =>
ReactDOMServerBrowser.renderToStaticNodeStream(<div />),
).toThrow(
'ReactDOMServer.renderToStaticNodeStream(): The streaming API is not available ' +
'in the browser. Use ReactDOMServer.renderToStaticMarkup() instead.',
);
});
});