Skip to content

Commit

Permalink
feat: add "keys" method
Browse files Browse the repository at this point in the history
  • Loading branch information
luckasnix committed Sep 14, 2024
1 parent 1cdc51f commit 44955b3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/object-graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ export class ObjectGraph<NodeValue extends Record<string, unknown>> {
}
}

/**
* @description Returns the keys of the object graph.
* @since 0.1.0
*/
public keys() {
return this.nodes.keys();
}

/**
* @description Returns the length of the object graph.
* @since 0.1.0
Expand Down
8 changes: 8 additions & 0 deletions tests/object-graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import {
type Size,
} from "../mocks/object-graph.mock";

describe("keys", () => {
test("get the keys of the object graph", () => {
const shirtsObjectGraph = new ObjectGraph<Shirt>(shirtsMock, (shirt) => shirt.sku);

expect(Array.from(shirtsObjectGraph.keys())).toEqual(["1", "2", "3", "4", "5", "6", "7", "8"]);
});
});

describe("length", () => {
test("get the length of the object graph", () => {
const shirtToAdd: Shirt = { sku: "9", color: "orange", size: "small" };
Expand Down

0 comments on commit 44955b3

Please sign in to comment.