/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * 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 */ 'use strict'; let React; let ReactDOMServer; describe('escapeTextForBrowser', () => { beforeEach(() => { jest.resetModules(); React = require('react'); ReactDOMServer = require('react-dom/server'); }); it('ampersand is escaped when passed as text content', () => { const response = ReactDOMServer.renderToString({'&'}); expect(response).toMatch('&'); }); it('double quote is escaped when passed as text content', () => { const response = ReactDOMServer.renderToString({'"'}); expect(response).toMatch('"'); }); it('single quote is escaped when passed as text content', () => { const response = ReactDOMServer.renderToString({"'"}); expect(response).toMatch('''); }); it('greater than entity is escaped when passed as text content', () => { const response = ReactDOMServer.renderToString({'>'}); expect(response).toMatch('>'); }); it('lower than entity is escaped when passed as text content', () => { const response = ReactDOMServer.renderToString({'<'}); expect(response).toMatch('<'); }); it('number is correctly passed as text content', () => { const response = ReactDOMServer.renderToString({42}); expect(response).toMatch('42'); }); it('number is escaped to string when passed as text content', () => { const response = ReactDOMServer.renderToString(); expect(response).toMatch(''); }); it('escape text content representing a script tag', () => { const response = ReactDOMServer.renderToString( {''}, ); expect(response).toMatch( '<script type='' ' + 'src=""></script>', ); }); });