Skip to content

Commit

Permalink
Make setDefaultXXXLabel chainable
Browse files Browse the repository at this point in the history
  • Loading branch information
cpettitt committed Sep 24, 2014
1 parent 8ad1e8e commit 27e7ee7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/base-graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,15 @@ BaseGraph.prototype.setDefaultNodeLabel = function(label) {
label = _.constant(label);
}
this._defaultNodeLabelFn = label;
return this;
};

BaseGraph.prototype.setDefaultEdgeLabel = function(label) {
if (!_.isFunction(label)) {
label = _.constant(label);
}
this._defaultEdgeLabelFn = label;
return this;
};


Expand Down
11 changes: 11 additions & 0 deletions test/base-graph-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ exports.tests = function(GraphConstructor) {
expect(g.getNode("a")).to.equal("a-label");
expect(g.getNode("b")).to.equal("b-label");
});

it("is chainable", function() {
var g2 = g.setDefaultNodeLabel(function() {});
expect(g).to.equal(g2);
});
});

describe("removeNode", function() {
Expand Down Expand Up @@ -466,7 +471,13 @@ exports.tests = function(GraphConstructor) {
g.setEdge("a", "b");
expect(g.getEdge("a", "b")).to.equal("a->b");
});

it("is chainable", function() {
var g2 = g.setDefaultEdgeLabel(function() {});
expect(g).to.equal(g2);
});
});

describe("removeEdge", function() {
it("does nothing if the edge is not in the graph", function() {
g.setNode("n1");
Expand Down

0 comments on commit 27e7ee7

Please sign in to comment.