Debian Codegraph @

__tests__/internal/unit/reference-sort-test.js

raw
1 import { _utilsReferenceSort as referenceSort } from "@lib";
2
3 describe("mirage:reference-sort", function () {
4 test("it sorts property references", () => {
5 let sorted = referenceSort([
6 ["propA"],
7 ["propB", "propC"],
8 ["propC", "propA"],
9 ["propD"],
10 ]);
11
12 expect(sorted).toEqual(["propD", "propA", "propC", "propB"]);
13 });
14
15 test("it throws on circular dependency", () => {
16 expect(function () {
17 referenceSort([
18 ["propA", "propB"],
19 ["propB", "propA"],
20 ]);
21 }).toThrow('Cyclic dependency in properties ["propB","propA"]');
22 });
23
24 test("it works with no references", () => {
25 let sorted = referenceSort([["propA"], ["propB"], ["propC"], ["propD"]]);
26
27 expect(sorted).toEqual(["propD", "propC", "propB", "propA"]);
28 });
29 });