/
githubmirror
/
react-beautiful-dnd
Обзор
Документация
Войти
/
githubmirror
/
react-beautiful-dnd
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/unit/integration/server-side-rendering/server-rendering.spec.js
66 строк
2 KB
Alex Reardon
12.0 (#1487)
29 окт 2019, 01:40
Не верифицирован
29 окт 2019, 01:40
24a8e60
Код
Авторство
О чём код?
/** * @jest-environment node */ // @flow import React from 'react'; import { renderToString, renderToStaticMarkup } from 'react-dom/server'; import { invariant } from '../../../../src/invariant'; import { resetServerContext } from '../../../../src'; import App from '../util/app'; const consoleFunctions: string[] = ['warn', 'error', 'log']; beforeEach(() => { // Reset server context between tests to prevent state being shared between them resetServerContext(); consoleFunctions.forEach((name: string) => { jest.spyOn(console, name); }); }); afterEach(() => { consoleFunctions.forEach((name: string) => { // eslint-disable-next-line no-console console[name].mockRestore(); }); }); const expectConsoleNotCalled = () => { consoleFunctions.forEach((name: string) => { // eslint-disable-next-line no-console expect(console[name]).not.toHaveBeenCalled(); }); }; // Checking that the browser globals are not available in this test file invariant( typeof window === 'undefined' && typeof document === 'undefined', 'browser globals found in node test', ); it('should support rendering to a string', () => { const result: string = renderToString(<App />); expect(result).toEqual(expect.any(String)); expect(result).toMatchSnapshot(); expectConsoleNotCalled(); }); it('should support rendering to static markup', () => { const result: string = renderToStaticMarkup(<App />); expect(result).toEqual(expect.any(String)); expect(result).toMatchSnapshot(); expectConsoleNotCalled(); }); it('should render identical content when resetting context between renders', () => { const firstRender = renderToString(<App />); const nextRenderBeforeReset = renderToString(<App />); expect(firstRender).not.toEqual(nextRenderBeforeReset); resetServerContext(); const nextRenderAfterReset = renderToString(<App />); expect(firstRender).toEqual(nextRenderAfterReset); expectConsoleNotCalled(); });