UNPKG

jest-prettyhtml-matchers

Version:

Custom Jest snapshot matchers that use prettyhtml to format strings.

26 lines 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createToMatchInlinePrettyHtmlSnapshot = void 0; const jest_snapshot_1 = require("jest-snapshot"); const create_formatter_1 = require("./create-formatter"); const createToMatchInlinePrettyHtmlSnapshot = (format) => function toMatchInlinePrettyHtmlSnapshot(received, options, inlineSnapshot) { if (typeof options === 'object') { format = (0, create_formatter_1.createFormatter)(options); } else { inlineSnapshot = options; } const error = new Error(); const newStack = error.stack .split(/\n/) .filter((_, index) => index !== 1) .join('\n'); error.stack = newStack; const newContext = Object.assign(Object.assign({}, this), { error }); if (inlineSnapshot) { return jest_snapshot_1.toMatchInlineSnapshot.call(newContext, format(received), inlineSnapshot); } return jest_snapshot_1.toMatchInlineSnapshot.call(newContext, format(received)); }; exports.createToMatchInlinePrettyHtmlSnapshot = createToMatchInlinePrettyHtmlSnapshot; //# sourceMappingURL=create-to-match-inline-prettyhtml-snapshot.js.map