UNPKG

chai-callslike

Version:

A simple sinon-chai assertion to validate many aspects of stub calls

25 lines (24 loc) 835 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stringify = void 0; const colors_1 = require("./colors"); const is_matcher_1 = require("./is-matcher"); const describe_matcher_1 = require("./describe-matcher"); function validDuplicity(v, objects) { if (typeof v === 'object' && v !== null) { if (objects.has(v)) { return colors_1.matchers('Circular'); } objects.add(v); } return v; } function stringifyEntry(objects) { return (_k, v) => is_matcher_1.isMatcher(v) ? describe_matcher_1.describeMatcher(v) : validDuplicity(v, objects); } function stringify(value) { const objects = new Set(); const result = JSON.stringify(value, stringifyEntry(objects)); return result || colors_1.matchers('undefined'); } exports.stringify = stringify;