mirror of
https://github.com/zhigang1992/probot.git
synced 2026-06-16 02:44:19 +08:00
39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
const EventEmitter = require('events').EventEmitter;
|
|
const expect = require('expect');
|
|
const Context = require('../lib/context');
|
|
const createRobot = require('../lib/robot');
|
|
|
|
describe('Robot', () => {
|
|
let webhook;
|
|
let robot;
|
|
|
|
beforeEach(() => {
|
|
webhook = new EventEmitter();
|
|
robot = createRobot({}, webhook);
|
|
});
|
|
|
|
describe('on', () => {
|
|
it('calls the callback', () => {
|
|
const spy = expect.createSpy();
|
|
const event = {};
|
|
|
|
robot.on('test', spy);
|
|
expect(spy).toNotHaveBeenCalled();
|
|
webhook.emit('test', event);
|
|
expect(spy).toHaveBeenCalled();
|
|
expect(spy.calls[0].arguments[0]).toBe(event);
|
|
expect(spy.calls[0].arguments[1]).toBeA(Context);
|
|
});
|
|
|
|
it('emits event with acton', () => {
|
|
const spy = expect.createSpy();
|
|
|
|
robot.on('test.bar', spy);
|
|
webhook.emit('test', {payload: {action: 'foo'}});
|
|
expect(spy).toNotHaveBeenCalled();
|
|
webhook.emit('test', {payload: {action: 'bar'}});
|
|
expect(spy).toHaveBeenCalled();
|
|
});
|
|
});
|
|
});
|