it-tools/src/tools/json-viewer/json.models.test.ts

17 lines
736 B
TypeScript
Raw Normal View History

2023-03-29 23:25:39 +02:00
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 } }),
);
});
});
});