Bind passed function to Robot by default
This commit is contained in:
parent
28415f0b74
commit
a17c70a18b
10
lib/robot.js
10
lib/robot.js
|
@ -54,10 +54,14 @@ var Robot = module.exports = function Robot(opts) {
|
|||
return;
|
||||
}
|
||||
|
||||
this[name] = opt;
|
||||
if (_.isFunction(opt)) {
|
||||
this[name] = opt.bind(this);
|
||||
|
||||
if (opts.commands == null && _.isFunction(opt)) {
|
||||
this.commands[name] = opt;
|
||||
if (opts.commands == null) {
|
||||
this.commands[name] = opt.bind(this);
|
||||
}
|
||||
} else {
|
||||
this[name] = opt;
|
||||
}
|
||||
}, this);
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ describe("Robot", function() {
|
|||
});
|
||||
|
||||
it("sets other obj params as values on the robot", function() {
|
||||
expect(robot.extraFunction).to.be.eql(extraFunction);
|
||||
expect(robot.extraFunction).to.be.a("function");
|
||||
expect(robot.extraValue).to.be.eql("Hello World");
|
||||
});
|
||||
|
||||
|
@ -96,7 +96,7 @@ describe("Robot", function() {
|
|||
});
|
||||
|
||||
it("sets #commands to the additionally provided functions", function() {
|
||||
expect(robot.commands).to.be.eql({ sayHello: robot.sayHello });
|
||||
expect(robot.commands.sayHello).to.be.a("function");
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue