我已经定义了两个玩笑模拟。我遇到的问题。第一个模拟不起作用,但第二个模拟起作用。
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
想用玩笑来模拟EventSource,但一直在抛ReferenceError: EventSource is not defined。
请看一下密码。非常感谢!
// eventSourceHandler.ts
export default new class A() {
listenEventSource(){
const eventSource = new EventSource(url);
eventSource.addEventListener("something", callSomething);
eventSource.onerror =
因此,我正在为我的一个函数编写一个测试用例,其中我调用了一个库的另一个函数,并试图模拟该函数(SaveCall),以下是示例代码: import { Call } from './somefolder/call';
class Demo {
var testIt = (params: any) => {
---- // Some other code
let call = new Call(params);
call.saveCall();
---- // Some other code
}
return {testIt: te
我如何模拟我正在用jest测试的一个类的依赖关系?
我有一个使用pigpio模块的类
// a trimmed down version of the class and method I'm writing a test for
import { Gpio } from "pigpio"
export default class BotController {
private initializePenActuator(): void {
this.penPause = Number(process.env.PEN_PAUSE_DELAY
我希望模拟类的实现,但随后执行断言,即在我的测试中调用了这些方法。
以下结果如下:
Error: expect(jest.fn()).toHaveBeenCalled()
Expected number of calls: >= 1
Received number of calls: 0
我假设这里不起作用的是我对测试文件中的const service = new Service();的调用正在创建模拟的一个新实例。
如何模拟类,但在测试的其他地方实例化时,如何确保返回相同的实例?
// ./service.ts
class Service {
getNothing() {
我正在尝试模拟Discord.JS模块。该模块有一个客户机类,我在"Bot“类中对其进行了扩展。我想模拟这个模块,这样我就可以在其他类上模拟一些方法,比如"Message“和"Channel",但是我想不出如何从NPM模块中模拟特定的类。试着在滑稽的文档和Google上找到一些东西,但是Google的结果只是链接到文档。我一直在接受这个问题,class extends value of undefined is not a constructor or null。这是我测试文件里的东西,
jest.mock('discord.js', () =&
我试着用动画模拟我的导入,但我一直收到
● Test suite failed to run
C:\work\portfolio\node_modules\gsap\TweenMax.js:13
import TweenLite, { TweenPlugin, Ease, Power0, Power1, Power2, Power3, Power4, Linear } from "./TweenLite.js";
^^^^^^^^^
SyntaxError: Unexpected identifier
该错误来自我的文件中的一个