You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-06 12:02:40 +03:00
Add functions to assist in immutability of Event objects
This commit is contained in:
@@ -2,7 +2,7 @@ import * as utils from "../../src/utils";
|
||||
import {
|
||||
alphabetPad,
|
||||
averageBetweenStrings,
|
||||
baseToString,
|
||||
baseToString, deepSortedObjectEntries,
|
||||
DEFAULT_ALPHABET,
|
||||
lexicographicCompare,
|
||||
nextString,
|
||||
@@ -429,4 +429,38 @@ describe("utils", function() {
|
||||
expect(lexicographicCompare('a', 'A') > 0).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('deepSortedObjectEntries', () => {
|
||||
it('should auto-return non-objects', () => {
|
||||
expect(deepSortedObjectEntries(42)).toEqual(42);
|
||||
expect(deepSortedObjectEntries("not object")).toEqual("not object");
|
||||
expect(deepSortedObjectEntries(true)).toEqual(true);
|
||||
expect(deepSortedObjectEntries([42])).toEqual([42]);
|
||||
expect(deepSortedObjectEntries(null)).toEqual(null);
|
||||
expect(deepSortedObjectEntries(undefined)).toEqual(undefined);
|
||||
});
|
||||
|
||||
it('should sort objects appropriately', () => {
|
||||
const input = {
|
||||
a: 42,
|
||||
b: {
|
||||
d: {},
|
||||
a: "test",
|
||||
b: "alpha",
|
||||
},
|
||||
[72]: "test",
|
||||
};
|
||||
const output = [
|
||||
["72", "test"],
|
||||
["a", 42],
|
||||
["b", [
|
||||
["a", "test"],
|
||||
["b", "alpha"],
|
||||
["d", []],
|
||||
]],
|
||||
];
|
||||
|
||||
expect(deepSortedObjectEntries(input)).toMatchObject(output);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user