aboutsummaryrefslogtreecommitdiff
path: root/src/tools/json-viewer/json.models.test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/json-viewer/json.models.test.ts')
-rw-r--r--src/tools/json-viewer/json.models.test.ts16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/tools/json-viewer/json.models.test.ts b/src/tools/json-viewer/json.models.test.ts
new file mode 100644
index 0000000..9bdcb23
--- /dev/null
+++ b/src/tools/json-viewer/json.models.test.ts
@@ -0,0 +1,16 @@
+import { describe, expect, it } from 'vitest';
+import { sortObjectKeys } from './json.models';
+
+describe('json models', () => {
+ describe('sortObjectKeys', () => {
+ it('the object keys are recursively sorted alphabetically', () => {
+ expect(JSON.stringify(sortObjectKeys({ b: 2, a: 1 }))).to.deep.equal(JSON.stringify({ a: 1, b: 2 }));
+ // To unsure that this way of testing is working
+ expect(JSON.stringify(sortObjectKeys({ b: 2, a: 1 }))).to.not.deep.equal(JSON.stringify({ b: 2, a: 1 }));
+
+ expect(JSON.stringify(sortObjectKeys({ b: 2, a: 1, d: { j: 7, a: [{ z: 9, y: 8 }] }, c: 3 }))).to.deep.equal(
+ JSON.stringify({ a: 1, b: 2, c: 3, d: { a: [{ y: 8, z: 9 }], j: 7 } }),
+ );
+ });
+ });
+});