Skip to content

Commit

Permalink
[Tests] add test coverage for options provided directly on a cmp func…
Browse files Browse the repository at this point in the history
…tion
ljharb committed Dec 16, 2024

Verified

This commit was signed with the committer’s verified signature.
ljharb Jordan Harband
1 parent 21e95e5 commit 0a50205
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/space.js
Original file line number Diff line number Diff line change
@@ -70,3 +70,29 @@ test('space parameter (same as native)', function (t) {
JSON.stringify(obj, null, ' ')
);
});

test('space parameter, on a cmp function', function (t) {
t.plan(3);
var obj = { one: 1, two: 2 };
var cmp = function (a, b) {
return a < b ? 1 : -1;
};

t.equal(
stringify(obj, { space: '\t' }),
'{\n\t"one": 1,\n\t"two": 2\n}',
'no cmp option (control)'
);
t.equal(
stringify(obj, { cmp: cmp, space: '\t' }),
'{\n\t"two": 2,\n\t"one": 1\n}',
'cmp option in the object'
);

cmp.space = '\t';
t.equal(
stringify(obj, cmp),
'{\n\t"two": 2,\n\t"one": 1\n}',
'cmp passed directly, with space option on it'
);
});

0 comments on commit 0a50205

Please sign in to comment.