chore: resolve unbound-method lint warnings in tests (#12204)

Capture jest mock references in local variables instead of asserting
against unbound method references on mocked classes/instances.

Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Tom Moor
2026-04-28 20:50:25 -04:00
committed by GitHub
parent e29c9102af
commit 4c85c4d08d
4 changed files with 27 additions and 35 deletions
@@ -5,9 +5,11 @@ import WebhookProcessor from "./WebhookProcessor";
jest.mock("../tasks/DeliverWebhookTask");
const ip = "127.0.0.1";
const schedule = jest.fn();
beforeEach(() => {
jest.resetAllMocks();
DeliverWebhookTask.prototype.schedule = schedule;
});
describe("WebhookProcessor", () => {
@@ -29,12 +31,8 @@ describe("WebhookProcessor", () => {
await processor.perform(event);
expect(
jest.mocked(DeliverWebhookTask.prototype.schedule)
).toHaveBeenCalled();
expect(
jest.mocked(DeliverWebhookTask.prototype.schedule)
).toHaveBeenCalledWith({
expect(schedule).toHaveBeenCalled();
expect(schedule).toHaveBeenCalledWith({
event,
subscriptionId: subscription.id,
});
@@ -57,9 +55,7 @@ describe("WebhookProcessor", () => {
await processor.perform(event);
expect(
jest.mocked(DeliverWebhookTask.prototype.schedule)
).toHaveBeenCalledTimes(0);
expect(schedule).toHaveBeenCalledTimes(0);
});
it("it schedules a delivery for the event for each subscription", async () => {
@@ -85,21 +81,13 @@ describe("WebhookProcessor", () => {
await processor.perform(event);
expect(
jest.mocked(DeliverWebhookTask.prototype.schedule)
).toHaveBeenCalled();
expect(
jest.mocked(DeliverWebhookTask.prototype.schedule)
).toHaveBeenCalledTimes(2);
expect(
jest.mocked(DeliverWebhookTask.prototype.schedule)
).toHaveBeenCalledWith({
expect(schedule).toHaveBeenCalled();
expect(schedule).toHaveBeenCalledTimes(2);
expect(schedule).toHaveBeenCalledWith({
event,
subscriptionId: subscription.id,
});
expect(
jest.mocked(DeliverWebhookTask.prototype.schedule)
).toHaveBeenCalledWith({
expect(schedule).toHaveBeenCalledWith({
event,
subscriptionId: subscriptionTwo.id,
});
@@ -6,8 +6,11 @@ import documentPermanentDeleter from "./documentPermanentDeleter";
jest.mock("@server/queues/tasks/DeleteAttachmentTask");
const schedule = jest.fn();
beforeEach(() => {
jest.resetAllMocks();
DeleteAttachmentTask.prototype.schedule = schedule;
});
describe("documentPermanentDeleter", () => {
@@ -62,9 +65,7 @@ describe("documentPermanentDeleter", () => {
await document.save();
const countDeletedDoc = await documentPermanentDeleter([document]);
expect(countDeletedDoc).toEqual(1);
expect(
jest.mocked(DeleteAttachmentTask.prototype.schedule)
).toHaveBeenCalledTimes(2);
expect(schedule).toHaveBeenCalledTimes(2);
expect(
await Document.unscoped().count({
where: {
+12 -9
View File
@@ -6,9 +6,10 @@ describe("Timeout middleware", () => {
const originalTimeout = 10000;
const newTimeout = 1800000; // 30 minutes
const setTimeout = jest.fn();
const mockSocket = {
timeout: originalTimeout,
setTimeout: jest.fn(),
setTimeout,
} as unknown as Socket;
const ctx = {
@@ -27,20 +28,21 @@ describe("Timeout middleware", () => {
);
// Should have set the new timeout
expect(mockSocket.setTimeout).toHaveBeenCalledWith(newTimeout);
expect(setTimeout).toHaveBeenCalledWith(newTimeout);
// Should have called next
expect(next).toHaveBeenCalled();
// Should have restored the original timeout
expect(mockSocket.setTimeout).toHaveBeenCalledWith(originalTimeout);
expect(setTimeout).toHaveBeenCalledWith(originalTimeout);
});
it("should restore original timeout even if next throws", async () => {
const originalTimeout = 10000;
const newTimeout = 1800000; // 30 minutes
const setTimeout = jest.fn();
const mockSocket = {
timeout: originalTimeout,
setTimeout: jest.fn(),
setTimeout,
} as unknown as Socket;
const ctx = {
@@ -62,19 +64,20 @@ describe("Timeout middleware", () => {
).rejects.toThrow("Test error");
// Should have set the new timeout
expect(mockSocket.setTimeout).toHaveBeenCalledWith(newTimeout);
expect(setTimeout).toHaveBeenCalledWith(newTimeout);
// Should have called next
expect(next).toHaveBeenCalled();
// Should have restored the original timeout even after error
expect(mockSocket.setTimeout).toHaveBeenCalledWith(originalTimeout);
expect(setTimeout).toHaveBeenCalledWith(originalTimeout);
});
it("should handle undefined original timeout", async () => {
const newTimeout = 1800000; // 30 minutes
const setTimeout = jest.fn();
const mockSocket = {
timeout: undefined,
setTimeout: jest.fn(),
setTimeout,
} as unknown as Socket;
const ctx = {
@@ -93,10 +96,10 @@ describe("Timeout middleware", () => {
);
// Should have set the new timeout
expect(mockSocket.setTimeout).toHaveBeenCalledWith(newTimeout);
expect(setTimeout).toHaveBeenCalledWith(newTimeout);
// Should have called next
expect(next).toHaveBeenCalled();
// Should have restored timeout to 0 when original was undefined
expect(mockSocket.setTimeout).toHaveBeenCalledWith(0);
expect(setTimeout).toHaveBeenCalledWith(0);
});
});
+2 -2
View File
@@ -310,9 +310,9 @@ describe("#removeDocument", () => {
const document = await buildDocument({ collectionId: collection.id });
await collection.reload();
jest.spyOn(collection, "save");
const saveSpy = jest.spyOn(collection, "save");
await collection.deleteDocument(document);
expect(collection.save).toHaveBeenCalled();
expect(saveSpy).toHaveBeenCalled();
});
it("should remove documents from root", async () => {