我正在尝试测试一个React组件,该组件的存储正在执行一些gRPC通信,因此需要node_module。我的测试是通过链接导入grpc,因为它导入了React组件,后者导入了存储,后者导入了grpc。
这很好,但是自动锁失败了:Error: The specified module could not be found. \\?\C:\Dev\Projects\Electron\PAT\client\app\node_modules\grpc\src\node\extension_binary\grpc_node.node
因此,我将一个模拟文件夹放置在每个Jest 的node_modules
我正在编写一个Electron应用程序,使用React作为前端,使用JEST + React Testing Library来运行测试。我在一个模块中有以下简化的代码: import React from 'react';
import { ipcRenderer } from 'electron';
import Paper from '@material-ui/core/Paper';
import LinearProgress from '@material-ui/core/LinearProgress';
const
我正在使用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 }
import Store from 'electron-store';
class Test {
private storeInstance: any;
public initialise() {
if(!Test.storeInstance) {
Test.storeInstance = new Store({name: 'test', key:123}); // returns Default
}
}
public getInstance() {
return Test.storeIn
我在很多地方都使用了一个模拟,所以我想将它移动到一个可以重用的单独文件中。
我想Jest把这叫做“人工模拟”。但是,我不想使用__mocks__约定。
正在测试的文件的顶部:
import * as dotenvSafe from "dotenv-safe";
手动模拟文件:
const dotenvSafe: any = jest.genMockFromModule("dotenv-safe");
dotenvSafe.load = jest.fn(() => { // the function I want to mock
return
我想模拟一个模块进行测试。一切正常,但我必须将相同的代码复制/粘贴到每个测试文件中。我怎样才能使它更易于维护?
(这是在TypeScript项目中使用Babel和Next.js。)
生产代码如下所示:
import { useRouter } from 'next/router';
// Then call the hook in a React component:
const router = useRouter();
测试代码:
// I need to access these mocks in the tests
const mockRouterPush = j
我正在尝试为一个模块创建一个简单的测试。我在一个模块中获得了一些firestore触发器(参见下面的模块文件)。在onDelete触发器中,我只想测试一下是否调用了deleteColletion。为此,我只需模拟出deleteCollection函数。在我的测试中(请参见测试文件中的onDelete should also delete the sub-collections trails and downloads ),我模拟deleteCollection函数并调用firestore触发器,并检查是否调用了deleteCollection。这是我从测试中得到的失败响应: Error: e
我已经定义了两个玩笑模拟。我遇到的问题。第一个模拟不起作用,但第二个模拟起作用。
import Helper from '../../test-helper'
import Storage from '@/storage'
import GuestContext from '@/auth/guest-context'
import UserContext from '@/auth/user-context'
// import LocalStorageGateway from '@/storage/local/loca
显然,mock.mockRestore()没有恢复使用jest.mock()创建的模拟的原始实现。
// a.js
export default class A {}
// b.js
import A from './a';
export default class B extends A {}
// test.js
import A from './a';
import B from './b';
jest.mock('./a');
jest.mock('./b');
const b = new B(
我试图重建一个电子应用程序,但我得到了这个错误的epoll安装。
Building module: epoll, Completed: 0gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp
✖ Rebuild Failed
An unhandled error occurred inside electron-rebuild
no