jestjs - How to get `this` in jest mock function -
i have below code, mocks function fetchage of person. need conditionally return value based on value of this, this empty object in function. there way in jest?
jest.unmock('person'); const person = require('person'); query.prototype.fetchage = jest.fn(() => { console.log(this); // returns empty object if(this.name === 'bob') return 21; if(this.name === 'joe') return 19; }); test('verify correct ages', function() { const bob = new person('bob'); expect(bob.fetchage).toequal(21); });
Comments
Post a Comment