management/front/dkha-web-sz-main/node_modules/object-hash/test/replacer.js

37 lines
974 B
JavaScript
Raw Normal View History

2023-12-18 13:12:25 +08:00
'use strict';
var assert = require('assert');
var stream = require('stream');
var hash = require('../index');
describe('replacer option', function() {
it('should emit information about an object to a stream', function() {
var strm = new stream.PassThrough();
var replacer = function(value) {
try {
return JSON.stringify(value);
} catch (e) {
return value;
}
};
var obj = {foo: 'bar'};
hash.writeToStream(obj, {replacer: replacer}, strm);
var result = strm.read().toString();
assert.strictEqual(typeof result, 'string');
assert.notStrictEqual(result.indexOf(JSON.stringify(obj)), -1);
});
it('should not reach property values when excludeValues = true', function() {
var strm = new stream.PassThrough();
var replacer = function(k) {
assert.notStrictEqual(k, 'bar');
return k;
};
hash.writeToStream({foo: 'bar'}, {excludeValues: true}, strm);
});
});