mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-08 19:18:02 +01:00
[PM-10654] Fixing broken jest tests (#10415)
This commit is contained in:
parent
6faa9f58ed
commit
320e4f18ce
@ -61,10 +61,13 @@ describe("AutofillInit", () => {
|
|||||||
autofillInit.init();
|
autofillInit.init();
|
||||||
jest.advanceTimersByTime(250);
|
jest.advanceTimersByTime(250);
|
||||||
|
|
||||||
expect(chrome.runtime.sendMessage).toHaveBeenCalledWith({
|
expect(chrome.runtime.sendMessage).toHaveBeenCalledWith(
|
||||||
command: "bgCollectPageDetails",
|
{
|
||||||
sender: "autofillInit",
|
command: "bgCollectPageDetails",
|
||||||
});
|
sender: "autofillInit",
|
||||||
|
},
|
||||||
|
expect.any(Function),
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("registers a window load listener to collect the page details if the document is not in a `complete` ready state", () => {
|
it("registers a window load listener to collect the page details if the document is not in a `complete` ready state", () => {
|
||||||
|
@ -37,10 +37,9 @@ describe("AutofillOverlayContentService", () => {
|
|||||||
);
|
);
|
||||||
autofillInit = new AutofillInit(autofillOverlayContentService);
|
autofillInit = new AutofillInit(autofillOverlayContentService);
|
||||||
autofillInit.init();
|
autofillInit.init();
|
||||||
sendExtensionMessageSpy = jest.spyOn(
|
sendExtensionMessageSpy = jest
|
||||||
autofillOverlayContentService as any,
|
.spyOn(autofillOverlayContentService as any, "sendExtensionMessage")
|
||||||
"sendExtensionMessage",
|
.mockResolvedValue(undefined);
|
||||||
);
|
|
||||||
Object.defineProperty(document, "readyState", {
|
Object.defineProperty(document, "readyState", {
|
||||||
value: defaultWindowReadyState,
|
value: defaultWindowReadyState,
|
||||||
writable: true,
|
writable: true,
|
||||||
|
@ -16,10 +16,8 @@ describe("InlineMenuFieldQualificationService", () => {
|
|||||||
forms: {},
|
forms: {},
|
||||||
fields: [],
|
fields: [],
|
||||||
});
|
});
|
||||||
chrome.runtime.sendMessage = jest.fn().mockImplementation((message) => ({
|
|
||||||
result: message.command === "getInlineMenuFieldQualificationFeatureFlag",
|
|
||||||
}));
|
|
||||||
inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService();
|
inlineMenuFieldQualificationService = new InlineMenuFieldQualificationService();
|
||||||
|
inlineMenuFieldQualificationService["inlineMenuFieldQualificationFlagSet"] = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("isFieldForLoginForm", () => {
|
describe("isFieldForLoginForm", () => {
|
||||||
|
@ -38,14 +38,24 @@ describe("generateRandomCustomElementName", () => {
|
|||||||
|
|
||||||
describe("sendExtensionMessage", () => {
|
describe("sendExtensionMessage", () => {
|
||||||
it("sends a message to the extension", async () => {
|
it("sends a message to the extension", async () => {
|
||||||
chrome.runtime.sendMessage = jest.fn().mockResolvedValue("sendMessageResponse");
|
const extensionMessagePromise = sendExtensionMessage("some-extension-message");
|
||||||
|
|
||||||
const response = await sendExtensionMessage("some-extension-message", { value: "value" });
|
// Jest doesn't give anyway to select the typed overload of "sendMessage",
|
||||||
|
// a cast is needed to get the correct spy type.
|
||||||
|
const sendMessageSpy = jest.spyOn(chrome.runtime, "sendMessage") as unknown as jest.SpyInstance<
|
||||||
|
void,
|
||||||
|
[message: string, responseCallback: (response: string) => void],
|
||||||
|
unknown
|
||||||
|
>;
|
||||||
|
|
||||||
expect(chrome.runtime.sendMessage).toHaveBeenCalledWith({
|
expect(sendMessageSpy).toHaveBeenCalled();
|
||||||
command: "some-extension-message",
|
|
||||||
value: "value",
|
const [latestCall] = sendMessageSpy.mock.calls;
|
||||||
});
|
const responseCallback = latestCall[1];
|
||||||
|
|
||||||
|
responseCallback("sendMessageResponse");
|
||||||
|
|
||||||
|
const response = await extensionMessagePromise;
|
||||||
expect(response).toEqual("sendMessageResponse");
|
expect(response).toEqual("sendMessageResponse");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user