OMG I've been here so many times. Finally, find the right solution for this. If you care only about espionage. Go to @Franey's answer. However, if you really need to specify a value for the recipient, 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)
})
})
source
share