【发布时间】:2016-04-09 18:32:50
【问题描述】:
如果我有一个 A 类,像这样:
class A{
constructor(foo){
this.foo = foo;
}
doStuff(){
//Code protected by an NDA, they'll nuke my house if I tell you what it does.
}
nukeHouse(){
//The implementation of this is somewhat buggy...
}
}
我希望 A 类的用户能够访问this.foo,所以我不想模拟构造函数。所有其他方法都应该被模拟。我可能可以手动说A.prototype.doStuff = jest.genMockFunction()ù, and do the same forA.prototype.nukeHouse`,但我希望有一种方法可以做到这一点,而不必每次向 A 添加方法时都更新模拟代码。
有没有办法做到这一点?
【问题讨论】:
标签: javascript mocking jestjs ecmascript-6