UNPKG

react-native-web-internals

Version:

React Native for Web

26 lines (25 loc) 1.91 kB
import { createSheet } from "../dom/index.mjs"; describe("createSheet", () => { test("creates a sheet on the client", () => { const sheet = createSheet(); expect(sheet.id).toMatchInlineSnapshot('"react-native-stylesheet"'), expect(typeof sheet.getTextContent()).toBe("string"), expect(typeof sheet.insert).toBe("function"); }), test("supports multiple documents with same styles", () => { const sheet = createSheet(); sheet.insert(".test-sheet { opacity: 1 }", 3); const iframe = document.createElement("iframe"); document.body.appendChild(iframe); const iframeDoc = iframe.contentWindow.document, iframeRootTag = document.createElement("div"); iframeDoc.body.appendChild(iframeRootTag); const iframeSheet = createSheet(iframeRootTag); expect(sheet).not.toBe(iframeSheet), expect(iframeSheet.id).toMatchInlineSnapshot('"react-native-stylesheet"'), expect(typeof iframeSheet.insert).toBe("function"), expect(iframeDoc.getElementById("react-native-stylesheet")).not.toBe(null), expect(iframeSheet.getTextContent().includes("test-sheet")).toBe(!0), sheet.insert(".test-iframe { opacity: 0 }", 3), expect(iframeSheet.getTextContent().includes("test-iframe")).toBe(!0); const shadowRoot = document.createElement("div").attachShadow({ mode: "open" }), shadowRootTag = document.createElement("div"); shadowRoot.appendChild(shadowRootTag), document.body.appendChild(shadowRoot); const shadowSheet = createSheet(shadowRootTag); expect(sheet).not.toBe(shadowSheet), expect(shadowSheet.id).toMatchInlineSnapshot('"react-native-stylesheet"'), expect(typeof shadowSheet.insert).toBe("function"), expect(shadowSheet.getTextContent().includes("test-sheet")).toBe(!0), sheet.insert(".test-shadow { opacity: 0 }", 3), expect(shadowSheet.getTextContent().includes("test-shadow")).toBe(!0); }); }); //# sourceMappingURL=dom-test.mjs.map