How do I spyOn Typescript getters and setters?
问题 When I unit test my getters are setters for Typescript, I cannot find a way to spy on those getters and setters. Instead, the object immediately gets evaluated. I am using Jasmine to unit test. 回答1: It is not supported yet, but there is a Jasmine issue for supporting getters. If you really need the support now, you can extend SpyRegistry.js file and add the code that apsillers proposed: this.spyOnProperty = function(obj, methodName, accessType) { ... var desc = Object.getPropertyDescriptor