UNPKG

declapract

Version:

A tool to declaratively define best practices, maintainable evolve them, and scalably enforce them.

29 lines 1.4 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkContainsSubstring = void 0; const expect_1 = __importDefault(require("expect")); const jest_diff_1 = require("jest-diff"); const UnexpectedCodePathError_1 = require("../../../../../../UnexpectedCodePathError"); const checkContainsSubstring = ({ declaredContents, foundContents, bAnnotation = 'Received', }) => { try { (0, expect_1.default)(foundContents).toContain(declaredContents); } catch (error) { // if the above check failed, run diff on the string directly to show a better string diff message const difference = (0, jest_diff_1.diff)(declaredContents, foundContents, { aAnnotation: 'Expected toContain', bAnnotation, }); if (!difference || difference === 'Compared values have no visual difference.') throw new UnexpectedCodePathError_1.UnexpectedCodePathError('expect().toContain() threw an error, but no difference was detected in the strings', { errorMessage: error.message, }); throw new Error(difference); } }; exports.checkContainsSubstring = checkContainsSubstring; //# sourceMappingURL=checkContainsSubstring.js.map