1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 09:13:33 +00:00

[PM-5189] Fixing jest tests

This commit is contained in:
Cesar Gonzalez
2024-04-18 12:09:08 -05:00
parent 71474320c5
commit ae390918aa
2 changed files with 7 additions and 17 deletions

View File

@@ -86,7 +86,7 @@ class AutofillInit implements AutofillInitInterface {
const sendCollectDetailsMessage = () => { const sendCollectDetailsMessage = () => {
this.clearCollectPageDetailsOnLoadTimeout(); this.clearCollectPageDetailsOnLoadTimeout();
this.collectPageDetailsOnLoadTimeout = setTimeout( this.collectPageDetailsOnLoadTimeout = setTimeout(
() => sendExtensionMessage("bgCollectPageDetails", { sender: "autofillInit" }), () => this.sendExtensionMessage("bgCollectPageDetails", { sender: "autofillInit" }),
250, 250,
); );
}; };
@@ -202,15 +202,6 @@ class AutofillInit implements AutofillInitInterface {
return true; return true;
}; };
/**
* Clears the send collect details message timeout.
*/
private clearSendCollectDetailsMessageTimeout() {
if (this.sendCollectDetailsMessageTimeout) {
clearTimeout(this.sendCollectDetailsMessageTimeout as number);
}
}
/** /**
* Handles destroying the autofill init content script. Removes all * Handles destroying the autofill init content script. Removes all
* listeners, timeouts, and object instances to prevent memory leaks. * listeners, timeouts, and object instances to prevent memory leaks.
@@ -221,7 +212,6 @@ class AutofillInit implements AutofillInitInterface {
this.collectAutofillContentService.destroy(); this.collectAutofillContentService.destroy();
this.autofillOverlayContentService?.destroy(); this.autofillOverlayContentService?.destroy();
this.inlineMenuElements?.destroy(); this.inlineMenuElements?.destroy();
this.clearSendCollectDetailsMessageTimeout();
} }
} }

View File

@@ -12,7 +12,7 @@ import { Fido2ClientService } from "@bitwarden/common/vault/services/fido2/fido2
import { createPortSpyMock } from "../../../autofill/spec/autofill-mocks"; import { createPortSpyMock } from "../../../autofill/spec/autofill-mocks";
import { import {
flushPromises, flushPromises,
sendExtensionRuntimeMessage, sendMockExtensionMessage,
triggerPortOnDisconnectEvent, triggerPortOnDisconnectEvent,
triggerRuntimeOnConnectEvent, triggerRuntimeOnConnectEvent,
} from "../../../autofill/spec/testing-utils"; } from "../../../autofill/spec/testing-utils";
@@ -263,7 +263,7 @@ describe("Fido2Background", () => {
it("ignores messages that do not have a handler associated with a command within the message", () => { it("ignores messages that do not have a handler associated with a command within the message", () => {
const message = mock<Fido2ExtensionMessage>({ command: "nonexistentCommand" }); const message = mock<Fido2ExtensionMessage>({ command: "nonexistentCommand" });
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
expect(abortManagerMock.abort).not.toHaveBeenCalled(); expect(abortManagerMock.abort).not.toHaveBeenCalled();
}); });
@@ -274,7 +274,7 @@ describe("Fido2Background", () => {
const sendResponse = jest.fn(); const sendResponse = jest.fn();
fido2ClientService.createCredential.mockRejectedValue(new Error("error")); fido2ClientService.createCredential.mockRejectedValue(new Error("error"));
sendExtensionRuntimeMessage(message, sender, sendResponse); sendMockExtensionMessage(message, sender, sendResponse);
await flushPromises(); await flushPromises();
expect(sendResponse).toHaveBeenCalledWith({ error: { message: "error" } }); expect(sendResponse).toHaveBeenCalledWith({ error: { message: "error" } });
@@ -287,7 +287,7 @@ describe("Fido2Background", () => {
abortedRequestId: "123", abortedRequestId: "123",
}); });
sendExtensionRuntimeMessage(message); sendMockExtensionMessage(message);
await flushPromises(); await flushPromises();
expect(abortManagerMock.abort).toHaveBeenCalledWith(message.abortedRequestId); expect(abortManagerMock.abort).toHaveBeenCalledWith(message.abortedRequestId);
@@ -302,7 +302,7 @@ describe("Fido2Background", () => {
data: mock<CreateCredentialParams>(), data: mock<CreateCredentialParams>(),
}); });
sendExtensionRuntimeMessage(message, senderMock); sendMockExtensionMessage(message, senderMock);
await flushPromises(); await flushPromises();
expect(fido2ClientService.createCredential).toHaveBeenCalledWith( expect(fido2ClientService.createCredential).toHaveBeenCalledWith(
@@ -323,7 +323,7 @@ describe("Fido2Background", () => {
data: mock<AssertCredentialParams>(), data: mock<AssertCredentialParams>(),
}); });
sendExtensionRuntimeMessage(message, senderMock); sendMockExtensionMessage(message, senderMock);
await flushPromises(); await flushPromises();
expect(fido2ClientService.assertCredential).toHaveBeenCalledWith( expect(fido2ClientService.assertCredential).toHaveBeenCalledWith(