UNPKG

declapract

Version:

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

26 lines 1.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.checkEqualsString = void 0; const expect_1 = __importDefault(require("expect")); const jest_diff_1 = require("jest-diff"); const UnexpectedCodePathError_1 = require("../../../../../../UnexpectedCodePathError"); const checkEqualsString = ({ declaredContents, foundContents, }) => { try { (0, expect_1.default)(foundContents).toEqual(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 toEqual', }); if (!difference || difference === 'Compared values have no visual difference.') throw new UnexpectedCodePathError_1.UnexpectedCodePathError('expect().toEqual() threw an error, but no difference was detected in the strings', { errorMessage: error.message }); throw new Error(difference); } }; exports.checkEqualsString = checkEqualsString; //# sourceMappingURL=checkEqualsString.js.map