问题标签 [automocking]

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 投票
1 回答
241 浏览

c# - 模拟时,IConfiguration 不断获取空值

我可以询问我是否正确地模拟了我的 IConfiguration,因为我一直收到一个空错误。我试图在读取 appsettings.json 的地方模拟我的控制器。

ControllerOne.cs

控制器测试.cs

ControllerTestsBase.cs

当我调试并跟踪到Controller.cs methodOne时,_configuration 一直提示 null 错误。

  • 为代码片段道歉,我再次更新了代码。
  • 我还意识到我之前在这里的帖子c# Mock IConfiguration keep get null正在关闭,因为我之前发布了一些无法编译的内容。
0 投票
1 回答
1750 浏览

debugging - AutoMock CreateInstance 要模拟的类型必须是接口、委托或非密封、非静态类

模拟“autoMocker.CreateInstance<HeliumController>();”时,我收到以下通用消息 与 Moq.AutoMock.Automocker。HeliumController 类的构造函数有几个接口。如何找到无法模拟的特定接口或构造函数?

0 投票
1 回答
984 浏览

typescript - 无法使用 typescript 用 jest 模拟 fs - 类型上不存在属性“mockReturnValue”

问题:

有人会帮我弄清楚如何使用打字稿开玩笑地模拟 fs 吗?我已经尝试了一些东西,这是主要的:

我正在尝试使用 jest 来模拟“fs”,但我似乎无法让 jest 在 Typescript 中自动模拟“fs”库。

这是我的代码:

打字稿告诉我“类型上不存在属性'mockReturnValue'......”

不能用玩笑来模拟 fs

环境:

节点 v14.15.1
打字稿:“^4.0.3”
VS 代码打字稿:4.1.2

在相关的说明中,我用 spyOn 尝试了这个,但失败了:

我尝试使用它但也无法spyOn工作(参考:jest typescript property mock does not exist on type

此代码失败并出现此打字稿错误 TS2345:

相关参考: