Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add "keys" method #38

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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