-
Notifications
You must be signed in to change notification settings - Fork 41
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
Mock dependencies #51
Comments
I was able to mock a dependency of my script by using mockery and sinon. Here's a snippet that shows an example: const mockery = require('mockery');
const sinon = require('sinon');
const Helper = require('hubot-test-helper');
const co = require('co');
const { expect } = require('chai');
const processFn = sinon.stub();
const mockApi = {
process: processFn
};
describe('script', () => {
beforeEach(() => {
const helper = new Helper('./script.js');
mockery.registerMock('./myApi'.js, mockApi);
mockery.enable({ warnOnUnregistered: false });
this.room = helper.createRoom({ httpd: false });
});
afterEach(() => {
this.room.destroy();
processFn.reset();
mockery.disable();
});
context('script', () => {
beforeEach(() => {
processFn.resolves('Hello!');
return co(function * () {
yield this.room.user.say('brian', '@hubot my regex');
}.bind(this));
});
it('returns', () => {
expect(this.room.messages).to.equal([
['brian', '@hubot my regex'],
['hubot', 'Hello!']
]);
});
});
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi
My code looks like:
myApi is a wrapper for Google Api. So, I want to test mocking my Api. I usually use proxyquire but I don't know because you only pass the path and don't do a require. Do you have any clue?
The text was updated successfully, but these errors were encountered: