V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐关注
Meteor
JSLint - a JavaScript code quality tool
jsFiddle
D3.js
WebStorm
推荐书目
JavaScript 权威指南第 5 版
Closure: The Definitive Guide
Flands
V2EX  ›  JavaScript

jest 中如何 mock 类其中的部分函数?

  •  1
     
  •   Flands · 2021-01-25 16:39:05 +08:00 · 1213 次点击
    这是一个创建于 1158 天前的主题,其中的信息可能已经有所发展或是发生改变。
    import { Recorder, Pubsub } from "trident";
    const pubsub = new Pubsub();
    
    export class SmartRecorder extends Recorder {
      constructor(props) {
        super(props);
      }
      start() {
        pubsub.subscribe('androidData', androidDataHandler);
        return super.start();
      }
    }
    

    使用 mockImplementation 方式,提示 类型“typeof Recorder”上不存在属性“mockImplementation” 使用 jest.requireActual,直接没法运行

    试了两天搜了很多方法都不行,请问下大佬们怎么编写啊?

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   4022 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 10:19 · PVG 18:19 · LAX 03:19 · JFK 06:19
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.