【问题标题】:Electron Jest Mock modulesElectron Jest Mock 模块
【发布时间】:2021-10-11 03:06:15
【问题描述】:

我正在使用 Spectron 测试我的电子应用程序。我正在使用带有 webpack 和 typescript 的电子锻造。

import { beforeEach, expect, test } from "@jest/globals";
import { setupBrowser, configure } from "@testing-library/webdriverio";
import si from "systeminformation";
import electronPath from "electron";
import { join } from "path";
import { Application } from "spectron";

let app;

jest.mock("systeminformation", () => ({
  get: () => ({
    mem: { total: 22 },
    uuid: { hardware: "hello-jake" },
  }),
}));

beforeAll(async () => {
  app = new Application({
    path: electronPath,
    args: [join(__dirname, "..")],
  });
  return app.start();
}, 15000);

电子应用使用systeminformation我想模拟它。

如何让它发挥作用? Webpack 已经编译好了代码。

【问题讨论】:

    标签: webpack jestjs electron spectron


    【解决方案1】:

    我想我有一个类似的问题,试图模拟电子本身,但它是一个 electron.exe 文件。我在猜测 exe 文件不是模块吗? 也许试试这个控制台日志?

    jest.mock('systeminformation', () => {
    const originalModule = jest.requireActual('systeminformation');
        console.log(originalModule);
      return {
        __esModule: true,
        ...originalModule,
       get: () => ({
        mem: { total: 22 },
        uuid: { hardware: "hello-jake" },
      }),
      };
    });
    

    对我来说,它返回了一个 .exe 文件的路径,这没用。我也尝试过使用正确的模块,并且得到了正确的方法。需要自己弄清楚,从哪里获得电子模块,或者也需要把它们弄出来。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-08-18
      • 2023-03-14
      • 1970-01-01
      • 2018-09-13
      • 2017-07-15
      • 2018-09-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多