UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

28 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StringContainsMatcher = void 0; const case_plugin_base_1 = require("@contract-case/case-plugin-base"); const check = async (matcher, matchContext, actual) => { const expectedInclusion = (0, case_plugin_base_1.mustResolveToString)(matcher['_case:matcher:contains'], matchContext); return (0, case_plugin_base_1.combineResults)(typeof actual === 'string' ? (0, case_plugin_base_1.errorWhen)(!actual.includes(expectedInclusion), (0, case_plugin_base_1.matchingError)(matcher, `The string '${actual}' did not include the expected substring '${expectedInclusion}'`, actual, matchContext)) : (0, case_plugin_base_1.makeResults)((0, case_plugin_base_1.matchingError)(matcher, `'${typeof actual}' is not a string`, actual, matchContext))); }; exports.StringContainsMatcher = { describe: (matcher, matchContext) => `a string containing "${(0, case_plugin_base_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 case_plugin_base_1.StripUnsupportedError(matcher, matchContext); }, validate: (matcher, matchContext) => Promise.resolve().then(() => { if ('_case:matcher:example' in matcher && typeof matcher['_case:matcher:example'] !== 'string') { throw new case_plugin_base_1.CaseConfigurationError(`The example provided to the string contains matcher was of type '${typeof matcher['_case:matcher:example']}' instead of string`, matchContext); } return matchContext.descendAndValidate(matcher['_case:matcher:contains'], (0, case_plugin_base_1.addLocation)(':stringContains', matchContext)); }), }; //# sourceMappingURL=StringContainsMatcher.js.map