-
-
Save mxriverlynn/11227280 to your computer and use it in GitHub Desktop.
mock objects in jasmine, with spies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Scheduling = require("Scheduling"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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