Properly mock crypto module

This commit is contained in:
Chloe Herd 2023-12-05 14:08:05 -05:00
parent 67c9b1609b
commit ef5a6a55e3

View file

@ -1,5 +1,5 @@
import analyticsMixin from "@/mixins/analytics-mixin";
import { setupMocksForJsFiles, setupCookies } from "@/helpers/unit-test-helper.js";
import { setupMocksForJsFiles, setupCookies, setupCrypto } from "@/helpers/unit-test-helper.js";
import { storeActions } from "@/constants/store-actions";
import {
analyticsPageEvents,
@ -11,19 +11,12 @@ import {
} from "@/constants/analytics";
import store from "@/store";
// Mock only the regenerate functions; window.crypto is not available in testing.
jest.mock("@/helpers/heritage-integration/cookie-helper", () => {
const originalModule = jest.requireActual("@/helpers/heritage-integration/cookie-helper");
return {
__esModule: true,
...originalModule,
regenerateDeviceId: jest.fn(),
regenerateUserId: jest.fn(),
};
});
describe("analyticsMixin.js", () => {
beforeEach(() => {
setupCrypto();
});
test("logPageView: calls dispatch with type and payload", async () => {
const type = "";
const payload = {};