Skip to content

Commit 0a50205

Browse files
committedDec 16, 2024
[Tests] add test coverage for options provided directly on a cmp function
1 parent 21e95e5 commit 0a50205

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
 

‎test/space.js

+26
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,29 @@ test('space parameter (same as native)', function (t) {
7070
JSON.stringify(obj, null, ' ')
7171
);
7272
});
73+
74+
test('space parameter, on a cmp function', function (t) {
75+
t.plan(3);
76+
var obj = { one: 1, two: 2 };
77+
var cmp = function (a, b) {
78+
return a < b ? 1 : -1;
79+
};
80+
81+
t.equal(
82+
stringify(obj, { space: '\t' }),
83+
'{\n\t"one": 1,\n\t"two": 2\n}',
84+
'no cmp option (control)'
85+
);
86+
t.equal(
87+
stringify(obj, { cmp: cmp, space: '\t' }),
88+
'{\n\t"two": 2,\n\t"one": 1\n}',
89+
'cmp option in the object'
90+
);
91+
92+
cmp.space = '\t';
93+
t.equal(
94+
stringify(obj, cmp),
95+
'{\n\t"two": 2,\n\t"one": 1\n}',
96+
'cmp passed directly, with space option on it'
97+
);
98+
});

0 commit comments

Comments
 (0)
Please sign in to comment.