mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-21 11:35:34 +01:00
Browser - Add jest-preset-angular
(#9412)
* add "jest-preset-angular/setup-jest" to browser app * use flushPromises rather than await a dummy promise * move the import of `page-script` into beforeAll rather than the describe scope * invoke the sendMessage callback rather than relying on a promise comparison
This commit is contained in:
parent
fb577a448e
commit
00c305dff3
@ -144,7 +144,7 @@ describe("AutofillInit", () => {
|
|||||||
.mockResolvedValue(pageDetails);
|
.mockResolvedValue(pageDetails);
|
||||||
|
|
||||||
const response = await autofillInit["handleExtensionMessage"](message, sender, sendResponse);
|
const response = await autofillInit["handleExtensionMessage"](message, sender, sendResponse);
|
||||||
await Promise.resolve(response);
|
await flushPromises();
|
||||||
|
|
||||||
expect(response).toBe(true);
|
expect(response).toBe(true);
|
||||||
expect(sendResponse).toHaveBeenCalledWith(pageDetails);
|
expect(sendResponse).toHaveBeenCalledWith(pageDetails);
|
||||||
|
@ -37,14 +37,29 @@ describe("generateRandomCustomElementName", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("sendExtensionMessage", () => {
|
describe("sendExtensionMessage", () => {
|
||||||
it("sends a message to the extention", () => {
|
it("sends a message to the extension", async () => {
|
||||||
const extensionMessageResponse = sendExtensionMessage("updateAutofillOverlayHidden", {
|
const extensionMessagePromise = sendExtensionMessage("updateAutofillOverlayHidden", {
|
||||||
display: "none",
|
display: "none",
|
||||||
});
|
});
|
||||||
jest.spyOn(chrome.runtime, "sendMessage");
|
|
||||||
|
|
||||||
expect(chrome.runtime.sendMessage).toHaveBeenCalled();
|
// Jest doesn't give anyway to select the typed overload of "sendMessage",
|
||||||
expect(extensionMessageResponse).toEqual(Promise.resolve({}));
|
// 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(sendMessageSpy).toHaveBeenCalled();
|
||||||
|
|
||||||
|
const [latestCall] = sendMessageSpy.mock.calls;
|
||||||
|
const responseCallback = latestCall[1];
|
||||||
|
|
||||||
|
responseCallback("sendMessageResponse");
|
||||||
|
|
||||||
|
const response = await extensionMessagePromise;
|
||||||
|
|
||||||
|
expect(response).toEqual("sendMessageResponse");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -53,7 +53,9 @@ describe("Fido2 page script with native WebAuthn support", () => {
|
|||||||
const mockCredentialAssertResult = createAssertCredentialResultMock();
|
const mockCredentialAssertResult = createAssertCredentialResultMock();
|
||||||
setupMockedWebAuthnSupport();
|
setupMockedWebAuthnSupport();
|
||||||
|
|
||||||
require("./page-script");
|
beforeAll(() => {
|
||||||
|
require("./page-script");
|
||||||
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
jest.resetModules();
|
jest.resetModules();
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import "jest-preset-angular/setup-jest";
|
||||||
|
|
||||||
// Add chrome storage api
|
// Add chrome storage api
|
||||||
const QUOTA_BYTES = 10;
|
const QUOTA_BYTES = 10;
|
||||||
const storage = {
|
const storage = {
|
||||||
|
Loading…
Reference in New Issue
Block a user