Skip to content
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

Not sure how to use mock-kue #6

Open
atlantageek opened this issue May 18, 2016 · 2 comments
Open

Not sure how to use mock-kue #6

atlantageek opened this issue May 18, 2016 · 2 comments

Comments

@atlantageek
Copy link

Trying to understand how to use mock-kue. The README says just require it. But I only want to use it during testing. Do I put an if statement around it or what? Or does mock-kue realize its running in a test environment and it doesnt look like it overrides the createQueue function. CreateQueue requires redis to be running on the PC. Is this expected.

@rtodea
Copy link

rtodea commented Sep 17, 2016

From looking at the source code, this does not mock a Redis connection.
i.e. createQueue will still throw something like:

Error: Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED 127.0.0.1:6379
at Object.exports._errnoException (util.js:1026:11)
    at exports._exceptionWithHostPort (util.js:1049:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1081:14)

If you provide a connection, then mock-kue will wrap around the Job object.
E.g.

// production-code.js
module.exports = {
  createJob: () => {
    require('kue')
      .createQueue()
      .create('some-job', {title: 'some-job-in-production'})
      .save();
  }
}
// test.js
const pc = require('./production-code');
require('mock-kue'); // it must be placed before calling `createJob`

pc.createJob(); // will not enqueue any job because of `mock-kue`

@fruch
Copy link

fruch commented Oct 13, 2016

why can't it mock the redis connection as well ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants