mirror of
https://github.com/bitwarden/browser
synced 2025-12-14 07:13:32 +00:00
[PM-18657] Fix clipboard tests calling console.warn (#13580)
* Fix clipboard tests calling console.warn * Change to jest.SpyInstance
This commit is contained in:
@@ -3,14 +3,19 @@ import { BrowserApi } from "../browser/browser-api";
|
||||
import BrowserClipboardService from "../services/browser-clipboard.service";
|
||||
|
||||
describe("OffscreenDocument", () => {
|
||||
const browserApiMessageListenerSpy = jest.spyOn(BrowserApi, "messageListener");
|
||||
const browserClipboardServiceCopySpy = jest.spyOn(BrowserClipboardService, "copy");
|
||||
const browserClipboardServiceReadSpy = jest.spyOn(BrowserClipboardService, "read");
|
||||
const consoleErrorSpy = jest.spyOn(console, "error");
|
||||
let browserClipboardServiceCopySpy: jest.SpyInstance;
|
||||
let browserClipboardServiceReadSpy: jest.SpyInstance;
|
||||
let browserApiMessageListenerSpy: jest.SpyInstance;
|
||||
let consoleErrorSpy: jest.SpyInstance;
|
||||
|
||||
// FIXME: Remove when updating file. Eslint update
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
||||
require("../offscreen-document/offscreen-document");
|
||||
beforeEach(async () => {
|
||||
browserApiMessageListenerSpy = jest.spyOn(BrowserApi, "messageListener");
|
||||
browserClipboardServiceCopySpy = jest.spyOn(BrowserClipboardService, "copy");
|
||||
browserClipboardServiceReadSpy = jest.spyOn(BrowserClipboardService, "read");
|
||||
consoleErrorSpy = jest.spyOn(console, "error").mockImplementation();
|
||||
|
||||
await import("./offscreen-document");
|
||||
});
|
||||
|
||||
describe("init", () => {
|
||||
it("sets up a `chrome.runtime.onMessage` listener", () => {
|
||||
@@ -47,6 +52,7 @@ describe("OffscreenDocument", () => {
|
||||
it("copies the message text", async () => {
|
||||
const text = "test";
|
||||
|
||||
browserClipboardServiceCopySpy.mockResolvedValueOnce(undefined);
|
||||
sendMockExtensionMessage({ command: "offscreenCopyToClipboard", text });
|
||||
await flushPromises();
|
||||
|
||||
@@ -56,6 +62,7 @@ describe("OffscreenDocument", () => {
|
||||
|
||||
describe("handleOffscreenReadFromClipboard", () => {
|
||||
it("reads the value from the clipboard service", async () => {
|
||||
browserClipboardServiceReadSpy.mockResolvedValueOnce("");
|
||||
sendMockExtensionMessage({ command: "offscreenReadFromClipboard" });
|
||||
await flushPromises();
|
||||
|
||||
|
||||
@@ -2,9 +2,10 @@ import BrowserClipboardService from "./browser-clipboard.service";
|
||||
|
||||
describe("BrowserClipboardService", () => {
|
||||
let windowMock: any;
|
||||
const consoleWarnSpy = jest.spyOn(console, "warn");
|
||||
let consoleWarnSpy: any;
|
||||
|
||||
beforeEach(() => {
|
||||
consoleWarnSpy = jest.spyOn(console, "warn").mockImplementation();
|
||||
windowMock = {
|
||||
navigator: {
|
||||
clipboard: {
|
||||
@@ -104,8 +105,6 @@ describe("BrowserClipboardService", () => {
|
||||
});
|
||||
|
||||
await BrowserClipboardService.read(windowMock as Window);
|
||||
|
||||
expect(consoleWarnSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -185,7 +185,9 @@ describe("Browser Utils Service", () => {
|
||||
describe("copyToClipboard", () => {
|
||||
const getManifestVersionSpy = jest.spyOn(BrowserApi, "manifestVersion", "get");
|
||||
const sendMessageToAppSpy = jest.spyOn(SafariApp, "sendMessageToApp");
|
||||
const clipboardServiceCopySpy = jest.spyOn(BrowserClipboardService, "copy");
|
||||
const clipboardServiceCopySpy = jest
|
||||
.spyOn(BrowserClipboardService, "copy")
|
||||
.mockResolvedValue(undefined);
|
||||
let triggerOffscreenCopyToClipboardSpy: jest.SpyInstance;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -281,7 +283,9 @@ describe("Browser Utils Service", () => {
|
||||
describe("readFromClipboard", () => {
|
||||
const getManifestVersionSpy = jest.spyOn(BrowserApi, "manifestVersion", "get");
|
||||
const sendMessageToAppSpy = jest.spyOn(SafariApp, "sendMessageToApp");
|
||||
const clipboardServiceReadSpy = jest.spyOn(BrowserClipboardService, "read");
|
||||
const clipboardServiceReadSpy = jest
|
||||
.spyOn(BrowserClipboardService, "read")
|
||||
.mockResolvedValue("");
|
||||
|
||||
beforeEach(() => {
|
||||
getManifestVersionSpy.mockReturnValue(2);
|
||||
|
||||
Reference in New Issue
Block a user