在使用jasmine.createSpyObj实用程序构建SpyObj时声明吸气剂属性? [英] Declaring getter property when building SpyObj using jasmine.createSpyObj utility?
本文介绍了在使用jasmine.createSpyObj实用程序构建SpyObj时声明吸气剂属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
让我说一堂课
class MyRealClass {
get propOne() { return stuffFromTheServer; }
}
在测试时,我想实现此功能:
When testing, I want to achieve this functionality:
const mockClass = {
get propOne() { return someStuff; }
}
jasmine.spyOnProperty(mockClass, 'propOne', 'get');
通过做这样的事情...
By doing something like this...
const spy = jasmine.createSpyObj('mockClass', [
{methodName: 'propOne', accessType: 'get'}
]);
换句话说,我想使用jasmine.createSpyObj
构建一个SpyObj<MyRealClass>
并将getter属性声明为methodName
数组中的方法(第二个参数是createSpyObj()
方法.
In other words, I want to build a SpyObj<MyRealClass>
using the jasmine.createSpyObj
and declare the getter properties as methods in the methodName
array (the second parameter the the createSpyObj()
method.
这可能吗?
推荐答案
通过此代码,我做到了令人惊讶的简单:
I did it surprisingly simple by this code:
const routerMock = jasmine.createSpyObj(['events']);
routerMock.events = of(new NavigationEnd(0, 'url1', 'url2'));
const serviceToTest = new SomeService(routerMock);
这篇关于在使用jasmine.createSpyObj实用程序构建SpyObj时声明吸气剂属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文