1 | 'use strict';
|
2 |
|
3 | var assert = require('assert');
|
4 | var stream = require('stream');
|
5 | var hash = require('../index');
|
6 |
|
7 | describe('replacer option', function() {
|
8 | it('should emit information about an object to a stream', function() {
|
9 | var strm = new stream.PassThrough();
|
10 |
|
11 | var replacer = function(value) {
|
12 | try {
|
13 | return JSON.stringify(value);
|
14 | } catch (e) {
|
15 | return value;
|
16 | }
|
17 | };
|
18 |
|
19 | var obj = {foo: 'bar'};
|
20 | hash.writeToStream(obj, {replacer: replacer}, strm);
|
21 | var result = strm.read().toString();
|
22 | assert.strictEqual(typeof result, 'string');
|
23 | assert.notStrictEqual(result.indexOf(JSON.stringify(obj)), -1);
|
24 | });
|
25 |
|
26 | it('should not reach property values when excludeValues = true', function() {
|
27 | var strm = new stream.PassThrough();
|
28 |
|
29 | var replacer = function(k) {
|
30 | assert.notStrictEqual(k, 'bar');
|
31 | return k;
|
32 | };
|
33 |
|
34 | hash.writeToStream({foo: 'bar'}, {excludeValues: true}, strm);
|
35 | });
|
36 | });
|