Skip to content

Commit 8f55d17

Browse files
rhendricblakeembrey
authored andcommitted
Improve test coverage (#18)
1 parent 062a910 commit 8f55d17

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

javascript-stringify.js

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,18 +195,11 @@
195195
'[object Boolean]': function (boolean) {
196196
return 'new Boolean(' + boolean + ')';
197197
},
198-
'[object Uint8Array]': function (array, indent) {
199-
return 'new Uint8Array(' + stringifyArray(array) + ')';
200-
},
201198
'[object Set]': function (array, indent, next) {
202-
if (typeof Array.from === 'function') {
203-
return 'new Set(' + stringify(Array.from(array), indent, next) + ')';
204-
} else return undefined;
199+
return 'new Set(' + stringify(Array.from(array), indent, next) + ')';
205200
},
206201
'[object Map]': function (array, indent, next) {
207-
if (typeof Array.from === 'function') {
208-
return 'new Map(' + stringify(Array.from(array), indent, next) + ')';
209-
} else return undefined;
202+
return 'new Map(' + stringify(Array.from(array), indent, next) + ')';
210203
},
211204
'[object RegExp]': String,
212205
'[object Function]': String,

test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ describe('javascript-stringify', function () {
9999
describe('Error', function () {
100100
it('should stringify', test(new Error('test'), "new Error('test')"));
101101
});
102+
103+
describe('unknown native type', function () {
104+
it('should be omitted', test({ k: process }, '{}'));
105+
});
102106
});
103107

104108
describe('ES6', function () {
@@ -183,6 +187,18 @@ describe('javascript-stringify', function () {
183187

184188
expect(result).to.equal('(function(){var x={a:{}};x.b=x.a;return x;}())');
185189
});
190+
191+
it('should restore repeated values with indentation', function () {
192+
var obj = {}
193+
var child = {};
194+
195+
obj.a = child;
196+
obj.b = child;
197+
198+
var result = stringify(obj, null, 2, { references: true })
199+
200+
expect(result).to.equal('(function () {\nvar x = {\n a: {}\n};\nx.b = x.a;\nreturn x;\n}())');
201+
});
186202
});
187203

188204
describe('custom spaces', function () {
@@ -299,5 +315,10 @@ describe('javascript-stringify', function () {
299315
'should get part of the object',
300316
test(obj, '{a:{b:{}}}', null, { maxDepth: 2 })
301317
);
318+
319+
it(
320+
'should get part of the object when tracking references',
321+
test(obj, '{a:{b:{}}}', null, { maxDepth: 2, references: true })
322+
);
302323
});
303324
});

0 commit comments

Comments
 (0)