node.js - 笑话 2 级深度
问题描述
我正在尝试从 A 类测试一个函数 funcA,该函数调用 B 类的 funcB,而 B 类的 funcB 又调用 C 类的 funcC。
class A {
funcA(){
const result = new B().funcB();
}}
class A {
funcA(){
const result = new C().funcc()+d;
}}
class C {
funcC(){
return a+b;
}}
测试课是这样的:
describe('class A testing', () => {
jest.mock('../../../impl/b');
jest.mock('../../../impl/b', () => {
funcB : jest.fn().mockImplementation( () => {return 5})
});
jest.mock('../../../impl/c', () => {
funcB : jest.fn().mockImplementation( () => {return 6})
});
it("testing funcA", () => {
const a = new A(context);
const val = a.funcA();
expect(val).toEqual(11);
})
}
)
所以我看到调用仍然是原始函数,而不是模拟的 funcB 和 funcC。我想知道我在哪里嘲笑错了?
解决方案
推荐阅读
- laravel-5 - Laravel Snappy PDF 找不到文件路径
- joomla3.0 - 模块中的类别标签 (mod_articles_categories)
- python - 如何将列表中的值添加到每一行的其他列表中?
- python - 集合的复杂性
- java - 使用 Apple (Netty) 的 ServiceTalk 作为带有 Jersey 的 RESTful API 并让我们加密 HTTPS
- r - GGplot 挑战
- iis - IIS 8.5 Windows Server 2012 ASP Classic/Active-X COM DLL 写入 UNC 共享文件夹时出现问题
- php - 为什么函数 rand 在方括号中?
- php - Wordpress - 显示部分内容
- spring - JPA 存储库按函数名称查询不等于