Skip to content

Instantly share code, notes, and snippets.

@mxriverlynn
Last active August 29, 2015 14:00
Show Gist options
  • Save mxriverlynn/11227280 to your computer and use it in GitHub Desktop.
Save mxriverlynn/11227280 to your computer and use it in GitHub Desktop.
mock objects in jasmine, with spies
var Scheduling = require("Scheduling");
describe("when running a schedule", function(){
var schedule, mc;
beforeEach(function(){
schedule = new Scheduling.Schedule();
schedule.build([]);
spyOn(schedule, "on");
mc = new MasterControl(schedule);
mc.run();
});
it("should listen for ready jobs", function(){
expect(schedule.on).toHaveBeenCalledWith("job.ready", jasmine.any(Function));
});
});
var Scheduling = require("Scheduling");
var util = require("util");
var events = require("events");
function MockSchedule(){
spyOn(this, "emit").andCallThrough();
spyOn(this, "on").andCallThrough();
this.processJobCompletion = jasmine.createSpy("processJobCompletion");
}
util.inherits(MockSchedule, events.EventEmitter);
module.exports = MockSchedule;
var MockSchedule = require("./helpers/MockSchedule");
describe("when running a schedule", function(){
var schedule, mc;
beforeEach(function(){
schedule = new MockSchedule();
schedule.build([]);
mc = new MasterControl(schedule);
mc.run();
});
it("should listen for ready jobs", function(){
expect(schedule.on).toHaveBeenCalledWith("job.ready", jasmine.any(Function));
});
});
var schedule = jasmine.createSpyObj('Schedule', ['emit', 'on', 'run', 'whateverMethodYouNeed']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment