UNPKG

@case-contract-testing/case

Version:

Next-generation contract testing suite

22 lines (21 loc) 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringContainsMatcher = void 0; const entities_1 = require("../../entities"); const results_1 = require("../../entities/results"); const check = async (matcher, matchContext, actual) => { const expectedInclusion = (0, entities_1.mustResolveToString)(matcher['case:matcher:contains'], matchContext); return (0, results_1.combineResults)(typeof actual === 'string' ? (0, results_1.errorWhen)(!actual.includes(expectedInclusion), (0, results_1.matchingError)(matcher, `The string '${actual}' did not include the expected substring '${expectedInclusion}'`, actual, matchContext)) : (0, results_1.makeResults)((0, results_1.matchingError)(matcher, `'${typeof actual}' is not a string`, actual, matchContext))); }; exports.StringContainsMatcher = { describe: (matcher, matchContext) => `a string containing "${(0, entities_1.mustResolveToString)(matcher['case:matcher:contains'], matchContext).replace(/^"+|"+$/g, '')}"`, check, strip: (matcher, matchContext) => { if ('case:matcher:example' in matcher) { return matcher['case:matcher:example']; } throw new entities_1.StripUnsupportedError(matcher, matchContext); }, };