可以在Jasmine中模拟对象索引器吗?

时间:2018-11-14 12:39:49

标签: unit-testing jasmine

我想模拟这个接口,并且只模拟单个属性。

代码:

interface TheService
{
    [index: number]: any;
    ...
}

测试

let theService: jasmine.SpyObj<TheService>;

beforeEach(() => {
    theService = jasmine.createSpyObj<TheService>('theService', [0]);
});

it('does something', () => {
    theService[0].and.returnValue({ dummy: 'test'});

    ...

    console.log(theService[0].dummy); // here I want to print "test"
});

这有可能在茉莉花中嘲笑索引器吗?

0 个答案:

没有答案