How can I spy on a getter property using jasmine?

前端 未结 6 1852
南笙
南笙 2020-12-14 06:02

How can I spy on a getter property using jasmine?

var o = { get foo() {}, };

spyOn(o, \'foo\').and.returnValue(\'bar\'); // Doesn\'t work.

6条回答
  •  一整个雨季
    2020-12-14 06:31

    I think the best way is to use spyOnProperty. It expects 3 properties and you need to pass get or set as third property.

    spyOnProperty(o, 'foo', 'get').and.returnValue('bar');
    

提交回复
热议问题