UNPKG

@case-contract-testing/case

Version:

Next-generation contract testing suite

22 lines (21 loc) 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringSuffixMatcher = void 0; const entities_1 = require("../../entities"); const context_1 = require("../../entities/context"); const results_1 = require("../../entities/results"); const check = async (matcher, matchContext, actual) => { if (typeof actual !== 'string') { return (0, results_1.makeResults)((0, results_1.matchingError)(matcher, `'${typeof actual}' is not a string`, actual, matchContext)); } return actual.endsWith(matcher['case:matcher:suffix']) ? matchContext.descendAndCheck(matcher['case:matcher:prefix'], (0, context_1.addLocation)(':suffix', matchContext), actual.substring(0, actual.length - matcher['case:matcher:suffix'].length)) : (0, results_1.makeResults)((0, results_1.matchingError)(matcher, `The string '${actual}' did not end with the expected suffix '${matcher['case:matcher:suffix']}'`, actual, matchContext)); }; exports.StringSuffixMatcher = { describe: (matcher, matchContext) => `"${matchContext .descendAndDescribe(matcher['case:matcher:prefix'], (0, context_1.addLocation)(':suffix', matchContext)) .replace(/^"+|"+$/g, '')}${matcher['case:matcher:suffix']}"`, check, strip: (matcher, matchContext) => `${(0, entities_1.mustResolveToString)(matcher['case:matcher:prefix'], (0, context_1.addLocation)(':suffix', matchContext))}${matcher['case:matcher:suffix']}`, };