问题标签 [ts-mockito]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
0 回答
17 浏览

angular - 如何使用 ts-mockito 模拟对象窗口以进行单元测试

我在 angular 内部有以下实现service,即所谓的AService.

定义environment如下

我的想法是,无论何时startDoSth调用,都window.location.href必须调用一次。这个想法的实现

但是,我得到了错误

TypeError:无法读取未定义的属性“getAllMatchingActions”

我猜这个实例window没有被模拟,然后测试使用真实实例,可能有不匹配的东西!?

因此,我有一个想法,使用ts-mockitostub 对象window,然后我可以验证行为甚至结果。不幸的是,我不知道该怎么做。有什么建议么?

0 投票
0 回答
29 浏览

typescript - 如何验证被调用了多少次间谍对象的方法

我想检查多少次被称为间谍对象的方法。我不想嘲笑它(我想测试它的功能)。下面的代码不起作用(预期“bar()”将被调用 1 次。但已被调用 0 次。)

0 投票
1 回答
131 浏览

node.js - runTransaction 中的模拟事务

我想在runTransaction函数中模拟代码。

示例代码:

我想模拟transaction,检查它是否用正确的数据 etc.pp 调用。

我设法模拟firestore()但不知道如何模拟transaction参数。

0 投票
1 回答
41 浏览

typescript - 如何在 ts-mock 中模拟导入的函数

我是打字稿的新手,并且在玩 aws-lambda。

我正在尝试对我的处理程序进行单元测试,因此我需要模拟服务类,以便它返回一些模拟数据

下面我有一个从域服务获取数据的简单函数。

处理程序:

在此处输入图像描述

服务:

在此处输入图像描述

测试:

在此处输入图像描述

当我使用 运行测试时npx mocha,它显示:

在此处输入图像描述