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

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -