Skip to content

Commit

Permalink
feat: added test for areEqualElements function
Browse files Browse the repository at this point in the history
  • Loading branch information
UlisesGascon committed Oct 28, 2023
1 parent 817d380 commit 65370f4
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 16 deletions.
44 changes: 44 additions & 0 deletions src/utils/comparator/areEqualElements.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { areEqualElements } from "./areEqualElements.ts";

const baseScoreElement = {
name: "foo",
score: 0,
reason: "sample reason",
details: ["sample detail"],
documentation: {
short: "documentation short",
url: "documentation url",
},
};

describe("util: areEqualElements", () => {
it("returns true if two elements are equal", () => {
expect(
areEqualElements(
{ ...baseScoreElement, details: ["foo"], reason: "foo" },
{ ...baseScoreElement, details: ["foo"], reason: "foo" },
),
).toBe(true);
});

it("returns false if two elements are not equal", () => {
expect(
areEqualElements(
{ ...baseScoreElement, details: ["foo"], reason: "foo" },
{ ...baseScoreElement, details: ["bar"], reason: "bar" },
),
).toBe(false);
expect(
areEqualElements(
{ ...baseScoreElement, details: ["foo"], reason: "foo" },
{ ...baseScoreElement, details: ["bar"], reason: "foo" },
),
).toBe(false);
expect(
areEqualElements(
{ ...baseScoreElement, details: ["foo"], reason: "foo" },
{ ...baseScoreElement, details: ["foo"], reason: "bar" },
),
).toBe(false);
});
});
10 changes: 10 additions & 0 deletions src/utils/comparator/areEqualElements.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ScoreElement } from "../../types";

export const areEqualElements = (
currentElement: ScoreElement,
previousElement: ScoreElement,
) =>
JSON.stringify(currentElement.details) ===
JSON.stringify(previousElement.details) &&
JSON.stringify(currentElement.reason) ===
JSON.stringify(previousElement.reason);
16 changes: 0 additions & 16 deletions src/utils/comparator/areEqualElements.tsx

This file was deleted.

1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"allowImportingTsExtensions": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
Expand Down

0 comments on commit 65370f4

Please sign in to comment.