Skip to content

Commit

Permalink
chore: remove toStrictEqualExcluding
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbi08 committed Dec 5, 2024
1 parent d394750 commit 8863be0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 50 deletions.
48 changes: 0 additions & 48 deletions packages/consumption/test/customMatchers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { SerializableBase } from "@js-soft/ts-serval";
import { set } from "lodash";
import { ErrorValidationResult, SuccessfulValidationResult, ValidationResult } from "../src";

expect.extend({
Expand Down Expand Up @@ -40,51 +38,6 @@ expect.extend({
}

return { pass: true, message: () => "" };
},

toStrictEqualExcluding(received: unknown, expected: unknown, ...excludes: string[]) {
if (received instanceof SerializableBase) {
received = received.toJSON();
}
if (expected instanceof SerializableBase) {
expected = expected.toJSON();
}

const receivedClone = JSON.parse(JSON.stringify(received));
const expectedClone = JSON.parse(JSON.stringify(expected));

excludes.forEach((exclud) => {
set(receivedClone, exclud, undefined);
set(expectedClone, exclud, undefined);
});

const matcherName = "toStrictEqual";
const options = {
comment: "deep equality",
isNot: this.isNot,
promise: this.promise
};

const pass = this.equals(receivedClone, expectedClone, undefined, true);

let message: string;
if (pass) {
message =
`${this.utils.matcherHint(matcherName, undefined, undefined, options)}\n\n` +
`Expected: not ${this.utils.printExpected(expectedClone)}\n${
this.utils.stringify(expectedClone) === this.utils.stringify(receivedClone) ? "" : `Received: ${this.utils.printReceived(receivedClone)}`
}`;
} else {
message = `${this.utils.matcherHint(matcherName, undefined, undefined, options)}\n\n${this.utils.printDiffOrStringify(
expectedClone,
receivedClone,
"Expected",
"Received",
this.expand ?? true
)}`;
}

return { message: () => message, pass };
}
});

Expand All @@ -93,7 +46,6 @@ declare global {
interface Matchers<R> {
successfulValidationResult(): R;
errorValidationResult(error?: { code?: string; message?: string | RegExp }): R;
toStrictEqualExcluding(expected: unknown, ...ignoreProperties: string[]): R;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IDatabaseConnection } from "@js-soft/docdb-access-abstractions";
import { AccountController, AttributeTagClient, ClientResult, Transport } from "@nmshd/transport";
import { spy, when } from "ts-mockito";
import { ConsumptionController } from "../../../src";
import { AttributeTagCollection, ConsumptionController } from "../../../src";
import { TestUtil } from "../../core/TestUtil";

describe("AttributeTagCollection", function () {
Expand Down Expand Up @@ -72,6 +72,6 @@ describe("AttributeTagCollection", function () {
when(mockedClient.getAttributeTagCollection()).thenResolve(ClientResult.ok(mockTags));
const tags = await consumptionController.attributes.getAttributeTagCollection();

expect(tags.toJSON()).toStrictEqualExcluding(mockTags, "@type");
expect(tags).toStrictEqual(AttributeTagCollection.from(mockTags));
});
});

0 comments on commit 8863be0

Please sign in to comment.