UNPKG

jest-serializer-react-helmet-async

Version:
67 lines 2.72 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; const React = __importStar(require("react")); const react_helmet_async_1 = require("react-helmet-async"); // The typedef for react-helmet-async doesn't include canUseDOM, even though it's in the docs. // Make TypeScript know it's there. react_helmet_async_1.HelmetProvider.canUseDOM = false; const ReactHelmetAsyncContextSerializer = { test(value) { return Boolean( // Does the value exist? value && value.base && value.base.toComponent && value.bodyAttributes && value.bodyAttributes.toComponent && value.htmlAttributes && value.htmlAttributes.toComponent && value.link && value.link.toComponent && value.meta && value.meta.toComponent && value.noscript && value.noscript.toComponent && value.script && value.script.toComponent && value.style && value.style.toComponent && value.title && value.title.toComponent); }, print(value, serialize) { // Recreate head from Helmet data const head = serialize(React.createElement("html", Object.assign({}, value.htmlAttributes.toComponent()), React.createElement("head", null, value.base.toComponent(), value.link.toComponent(), value.meta.toComponent(), value.noscript.toComponent(), value.script.toComponent(), value.style.toComponent(), value.title.toComponent()), React.createElement("body", Object.assign({}, value.bodyAttributes.toComponent())))); // Return recreated head return head; }, }; module.exports = ReactHelmetAsyncContextSerializer; //# sourceMappingURL=index.js.map