Jest has an option to mock node_module
:
jest.mock('module_name')
Module I am trying to mock is cote
module.
Here is an index.js file from the module.
inside it has contructor for Requester
exported
const Requester = require('./components/requester');
...
cote.Requester = Requester;
...
module.exports = cote();
I access this file in my code like this:
const cote = require('cote');
const requester = new cote.Requester({name: 'findOnePlayer requester'});
...
const player = await requester.send({type:'findOnePlayer',username:username, password: password})
How to set up with jest
so that constructor of Requester
from mocked cote
module returns mocked object that resolves a promise when you call send?
EDIT:
I need this case in many tests, and each send(...
should return different promise per test scenario.