1
0
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:
Travis Ralston
2021-06-07 20:08:00 -06:00
parent 9f6ed4fb33
commit 13c9c4bea5
4 changed files with 156 additions and 1 deletions

View File

@@ -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);
});
});
});