UNPKG

@case-contract-testing/case

Version:

Next-generation contract testing suite

17 lines (16 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.NumberMatcher = void 0; const results_1 = require("../../../entities/results"); const testExactMatch_1 = require("./internal/testExactMatch"); const check = (matcher, matchContext, actual) => (0, results_1.combineResults)((0, results_1.errorWhen)(matchContext['case:context:matchBy'] === 'exact', (0, testExactMatch_1.testExactMatch)(matcher, matchContext, actual)), (0, results_1.errorWhen)(typeof actual !== 'number', (0, results_1.matchingError)(matcher, `'${typeof actual}' is not a number`, actual, matchContext)), (0, results_1.errorWhen)(matchContext['case:context:serialisableTo'] === 'json' && Number.isNaN(actual), (0, results_1.matchingError)(matcher, 'NaN is not a valid JSON number', actual, matchContext)), (0, results_1.errorWhen)(matchContext['case:context:serialisableTo'] === 'json' && typeof actual === 'number' && !Number.isFinite(actual), (0, results_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'], };