我正在使用Spectron来测试我的电子应用程序。我用的是电子锻造,还有webpack和打字稿。
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已经编译了代码。
发布于 2021-10-22 17:01:47
我想我也有类似的问题,我试着模拟电子本身,但它是一个electron.exe文件。我是gussing 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文件的路径,这是无用的。我还尝试了一个正确的模块,并且我得到了正确的方法。我需要自己弄清楚,从哪里得到电子模块,或者需要把它们也弄出来。
https://stackoverflow.com/questions/68677876
复制相似问题