Queston: Is it possible to unit test named job proccess handler calls with jest? #2010
-
DescriptionHello, I would like to know if its possible to test named job processor calls after call the queue Minimal, Working Test code to reproduce the issue.Looking to accomplish something like: // worker.js
const redisHost = require('my-redis-host'),
Queue = require('bull'),
fruitQueue = new Queue('fruitQueue', redisHost);
// consumer handler
const fruitHandler = (job) => {
const { fruitId } = job.data;
// my logic
}
// consumer
fruitQueue.process('updateFruit', 1, fruitHandler);
module.exports = { fruitQueue, fruitHandler } // worker.test.js
test(`Should call the fruitHandler`, () => {
const worker = require('./worker'),
job = {
fruitId: 1
};
worker.fruitHandler = jest.fn(() => Promise.resolve({}));
// calling the producer
fruitQueue.add('updateFruit', job);
worker.fruitHandler).toHaveBeenCalledTimes(1)
// also tried waiting
// setTimeout(expect(worker.updateInElasticById).toHaveBeenCalledTimes(1), 1000)
); The response always is:
Bull version3.20.1 Additional informationI've already tried mocking the bull lib. Also, ioredis-mock following this thread and of course using fully working redis instance up and running. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
I am having the same issue as well. Any thoughts on this? |
Beta Was this translation helpful? Give feedback.
-
I also have the same issue. Has anyone managed to find a solution to this ? |
Beta Was this translation helpful? Give feedback.
-
As I see it you could just unit test the handler isolated from the process function, just make sure that you properly mock the "job" object that you pass to the handler. |
Beta Was this translation helpful? Give feedback.
-
Same issue here |
Beta Was this translation helpful? Give feedback.
As I see it you could just unit test the handler isolated from the process function, just make sure that you properly mock the "job" object that you pass to the handler.