UNPKG

@contract-case/case-core

Version:

Core functionality for the ContractCase contract testing suite

18 lines 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberMatcher = void 0; const case_plugin_base_1 = require("@contract-case/case-plugin-base"); const testExactMatch_1 = require("./internal/testExactMatch"); const check = (matcher, matchContext, actual) => (0, case_plugin_base_1.combineResults)((0, case_plugin_base_1.errorWhen)(matchContext['_case:context:matchBy'] === 'exact', (0, testExactMatch_1.testExactMatch)(matcher, matchContext, actual)), (0, case_plugin_base_1.errorWhen)(typeof actual !== 'number', (0, case_plugin_base_1.matchingError)(matcher, `'${typeof actual}' is not a number`, actual, matchContext)), (0, case_plugin_base_1.errorWhen)(matchContext['_case:context:serialisableTo'] === 'json' && Number.isNaN(actual), (0, case_plugin_base_1.matchingError)(matcher, 'NaN is not a valid JSON number', actual, matchContext)), (0, case_plugin_base_1.errorWhen)(matchContext['_case:context:serialisableTo'] === 'json' && typeof actual === 'number' && !Number.isFinite(actual), (0, case_plugin_base_1.matchingError)(matcher, 'JSON numbers must be finite', actual, matchContext))); exports.NumberMatcher = { describe: (matcher, matchContext) => matchContext['_case:context:matchBy'] === 'exact' ? `${matcher['_case:matcher:example']}` : '<any number>', check, strip: (matcher) => matcher['_case:matcher:example'], validate: () => Promise.resolve(), }; //# sourceMappingURL=NumberMatcher.js.map