@contract-case/case-plugin-base
Version:
Plugin framework for writing plugins for the ContractCase test framework
36 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultNameMock = void 0;
const lookup_1 = require("../matchers/lookup");
/**
* Helper function that will generate and save a name for this matcher if it
* isn't already named.
*
* @param matcher - a matcher object
* @param context - the {@link MatchContext} for this run
* @returns a matcher object guaranteed to have a uniqueName
*/
const nameMatcher = (matcher, context) => typeof matcher === 'object' &&
matcher != null &&
'_case:matcher:uniqueName' in matcher
? matcher
: (0, lookup_1.coreLookupMatcher)(context.descendAndDescribe(matcher, context), matcher);
/**
* Helper function that will name this mock if it isn't already named.
* @public
* @remarks
*
* You probably don't need to use this function, it is used by ContractCase internals.
* TODO: it could be moved to the core.
*
* @param mock - a Mock Descriptor object
* @param context - the {@link MatchContext} for this run
* @returns a mock descriptor object where the request and response are guaranteed to be named.
*/
const defaultNameMock = (mock, context) => ({
...mock,
...(mock.request ? { request: nameMatcher(mock.request, context) } : {}),
...(mock.response ? { response: nameMatcher(mock.response, context) } : {}),
});
exports.defaultNameMock = defaultNameMock;
//# sourceMappingURL=names.js.map