Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queston: Is it possible to unit test named job proccess handler calls with jest? #2009

Closed
ealcantara22 opened this issue Apr 8, 2021 · 0 comments

Comments

@ealcantara22
Copy link

Description

Hello, I would like to know if its possible to test named job processor calls after call the queue add method using jest. Also, an example of how to accomplish this would be great.

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:

Error: expect(jest.fn()).toHaveBeenCalledTimes(expected)

Expected number of calls: 1
Received number of calls: 0

Bull version

3.20.1

Additional information

I've already tried mocking the bull lib. Also, ioredis-mock following this thread and of course using fully working redis instance up and running.

@ealcantara22 ealcantara22 changed the title Queston: Is it possible to unit test named job proccess hanlder calls with jest? Queston: Is it possible to unit test named job proccess handler calls with jest? Apr 8, 2021
@manast manast closed this as completed Apr 8, 2021
@OptimalBits OptimalBits locked and limited conversation to collaborators Apr 8, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants