显然,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(
注意:我将src/nod_modules文件夹中的所有代码直接移动到src文件夹中,并按照以下短线程:删除src/node_modules,从而修复了这个问题。
我使用的是创建-反应-应用程序和运行Jest有困难。
当我试图将任何一个响应组件导入到我的测试文件中时,当我yarn test时会得到一个错误。
Test suite failed to run
.../src/node_modules/common/ErrorMessage.js:1
({"Object.<anonymous>":function(
module,exports,require,__d
我正在使用Jest运行一些测试,并遇到了一个问题,我正在使用的一个模块。问题是,我正在尝试导入一个在构建时没有编译的模块。我所说的“不编译”的意思是,imports被保留在我试图导入到另一个文件的顶部。我的意思是:
jest.mock('@my-org/my-package/dist/browser');
import * as NTracking from '@my-org/my-package/dist/browser';
import generateStubs from '../test-jest/fixtures/client-stubs
一段时间以来,我一直试图模拟fetchLiveMatches导入的函数,但没有成功。我一直在浏览一些想法,但我想我已经用完了,所以我需要一些帮助。你知道我做错了什么吗?
live.test.js
import * as liveController from "./live";
import { jest } from "@jest/globals";
import * as liveService from "../service/live";
import { buildReq, buildRes, buildNext } from "
Jest测试在调用外部函数之后调用了一个闭包(一个内部函数),我遇到了问题。我尝试过使用spyOn,但没有得到积极的结果。这似乎是一个相对简单的问题,我还没有找到谷歌搜索的任何结果。
// helper.js
export const bar = () => {}
export const foo = () => {
bar(); //How do I test that this has been called?
}
//helper.test.js
import * as H from 'helper';
const barSpy = jest.spy
我有一个简单的Node.js 16.x应用程序。它使用ES模块,所以我在package.json中使用了package.json。每当我使用npm脚本时,一切都很好。
现在我尝试使用Docker来部署它,我不再需要npm脚本了,所以我直接使用node二进制文件启动应用程序,就像我在package.json:node --require dotenv/config main.js ...but中声明它不工作一样,它失败了,出现了围绕ES模块的典型错误消息等等:
(node:9) Warning: To load an ES module, set "type": "mod
我正在尝试使用类型记录中的request()来模拟节点模块request的jest函数,但是我做不到,有人能帮我哪里出了问题吗?顺便说一句,我正在尝试创建一个通用的代理函数,它应该与所有的http方法一起工作,比如get、post、delete、update。因此,我只想使用request()函数,而不是使用request.get(),request.post()...etc,使用基于request方法的if- method梯子。
Proxy.ts:
import * as request from 'request';
export default class ProxyC
我正在尝试使用Jest在Vue中建立单元测试。但是,我得到了这个错误:
● Test suite failed to run
...
SyntaxError: Cannot use import statement outside a module
>1 | import editUser from '@/components/forms/editUser.vue';
| ^
2 | import TestComponent from '@/pages/user/UserMyProfile.vue';
3 | import { shal
我运行jest测试文件并获得以下错误:
● Test suite failed to run
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.
Out of the box Jest support
像其他许多人一样,我正在尝试将我的RN应用程序升级到React-Native 0.56,而Babel正在让一切变得如此简单!(这里不是讽刺)我可以更新RN,对最新版本做出反应,让我的应用程序编译并工作,但测试(jest)不再起作用。
但不是所有的测试。我设法解决了几乎所有不同类型的问题,除了这一点:
meeting actions › creates CLEAR_CURRENT_ATTACHMENTS when clearning current attachments
TypeError: eventActions.refreshEvents.mockImplementation is n
我想用Jest对这个TS代码进行单元测试
MyClass.ts
import Dependency from "./Dependency";
export default class MyClass {
public constructor(private dependency: Dependency) {}
public DoIt(): string {
return this.dependency.MyProp;
}
}
它使用这个类:
export default class Dependency {
public ge