|
| 1 | +/** |
| 2 | + * Copyright (c) Facebook, Inc. and its affiliates. |
| 3 | + * |
| 4 | + * This source code is licensed under the MIT license found in the |
| 5 | + * LICENSE file in the root directory of this source tree. |
| 6 | + * |
| 7 | + * @emails react-core |
| 8 | + */ |
| 9 | + |
| 10 | +'use strict'; |
| 11 | + |
| 12 | +let React; |
| 13 | +let ReactDOM; |
| 14 | +let ReactDOMFizzServer; |
| 15 | + |
| 16 | +describe('react-dom-server-rendering-stub', () => { |
| 17 | + beforeEach(() => { |
| 18 | + jest.mock('react-dom', () => require('react-dom/server-rendering-stub')); |
| 19 | + |
| 20 | + React = require('react'); |
| 21 | + ReactDOM = require('react-dom'); |
| 22 | + ReactDOMFizzServer = require('react-dom/server'); |
| 23 | + }); |
| 24 | + |
| 25 | + it('exports a version', () => { |
| 26 | + expect(ReactDOM.version).toBeTruthy(); |
| 27 | + }); |
| 28 | + |
| 29 | + it('exports that are expected to be client only in the future are not exported', () => { |
| 30 | + expect(ReactDOM.createRoot).toBe(undefined); |
| 31 | + expect(ReactDOM.hydrateRoot).toBe(undefined); |
| 32 | + expect(ReactDOM.findDOMNode).toBe(undefined); |
| 33 | + expect(ReactDOM.hydrate).toBe(undefined); |
| 34 | + expect(ReactDOM.render).toBe(undefined); |
| 35 | + expect(ReactDOM.unmountComponentAtNode).toBe(undefined); |
| 36 | + expect(ReactDOM.unstable_batchedUpdates).toBe(undefined); |
| 37 | + expect(ReactDOM.unstable_createEventHandle).toBe(undefined); |
| 38 | + expect(ReactDOM.unstable_flushControlled).toBe(undefined); |
| 39 | + expect(ReactDOM.unstable_isNewReconciler).toBe(undefined); |
| 40 | + expect(ReactDOM.unstable_renderSubtreeIntoContainer).toBe(undefined); |
| 41 | + expect(ReactDOM.unstable_runWithPriority).toBe(undefined); |
| 42 | + }); |
| 43 | + |
| 44 | + // @gate enableFloat |
| 45 | + it('provides preload and preinit exports', async () => { |
| 46 | + function App() { |
| 47 | + ReactDOM.preload('foo', {as: 'style'}); |
| 48 | + ReactDOM.preinit('bar', {as: 'style'}); |
| 49 | + return <div>foo</div>; |
| 50 | + } |
| 51 | + const html = ReactDOMFizzServer.renderToString(<App />); |
| 52 | + expect(html).toEqual( |
| 53 | + '<link href="foo" rel="preload" as="style"/><link rel="stylesheet" href="bar" data-rprec="default"/><div>foo</div>', |
| 54 | + ); |
| 55 | + }); |
| 56 | + |
| 57 | + it('provides a stub for createPortal', async () => { |
| 58 | + expect(() => { |
| 59 | + ReactDOM.createPortal(); |
| 60 | + }).toThrow( |
| 61 | + 'createPortal was called on the server. Portals are not currently supported on the server. Update your program to conditionally call createPortal on the client only.', |
| 62 | + ); |
| 63 | + }); |
| 64 | + |
| 65 | + it('provides a stub for flushSync', async () => { |
| 66 | + let x = false; |
| 67 | + expect(() => { |
| 68 | + ReactDOM.flushSync(() => (x = true)); |
| 69 | + }).toThrow( |
| 70 | + 'flushSync was called on the server. This is likely caused by a function being called during render or in module scope that was intended to be called from an effect or event handler. Update your to not call flushSync no the server.', |
| 71 | + ); |
| 72 | + expect(x).toBe(false); |
| 73 | + }); |
| 74 | +}); |
0 commit comments