In Sinon I can do the following:
var myObj = {
prop: \'foo\'
};
sinon.stub(myObj, \'prop\').get(function getterFn() {
return \'bar\';
});
myObj.prop; /
OMG I've been here so many times. Finally figure out the proper solution for this. If you care about spying only. Go for @Franey 's answer. However if you actually need to stub a value for the getter this is how you can do it
class Awesomeness {
get isAwesome() {
return true
}
}
describe('Awesomeness', () => {
it('is not always awesome', () => {
const awesomeness = new Awesomeness
jest.spyOn(awesomeness, 'isAwesome', 'get').mockReturnValue(false)
expect(awesomeness.isAwesome).toEqual(false)
})
})