Commit a5461140 authored by Masayuki Tanaka's avatar Masayuki Tanaka

Avoid binding 3rd party property to c3 API - #647

parent 054f8517
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
// bind "this" to nested API // bind "this" to nested API
(function bindThis(fn, target, argThis) { (function bindThis(fn, target, argThis) {
for (var key in fn) { Object.keys(fn).forEach(function (key) {
target[key] = fn[key].bind(argThis); target[key] = fn[key].bind(argThis);
if (Object.keys(fn[key]).length > 0) { if (Object.keys(fn[key]).length > 0) {
bindThis(fn[key], target[key], argThis); bindThis(fn[key], target[key], argThis);
} }
} });
})(c3_chart_fn, this, this); })(c3_chart_fn, this, this);
} }
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -8,35 +8,52 @@ describe('c3 chart', function () { ...@@ -8,35 +8,52 @@ describe('c3 chart', function () {
var chart, d3; var chart, d3;
beforeEach(function () { var args = {
window.initDom(); data: {
columns: [
chart = window.c3.generate({ ['data1', 30, 200, 100, 400, 150, 250],
data: { ['data2', 50, 20, 10, 40, 15, 25],
columns: [ ['data3', 150, 120, 110, 140, 115, 125]
['data1', 30, 200, 100, 400, 150, 250], ]
['data2', 50, 20, 10, 40, 15, 25], }
['data3', 150, 120, 110, 140, 115, 125] };
]
} beforeEach(function (done) {
}); chart = window.initChart(chart, args, done);
d3 = chart.internal.d3; d3 = chart.internal.d3;
}); });
it('should be created', function () { describe('init', function () {
var svg = d3.select('#chart svg');
expect(svg).not.toBeNull(); it('should be created', function () {
}); var svg = d3.select('#chart svg');
expect(svg).not.toBeNull();
});
it('should set 3rd party property to Function', function () {
Function.prototype.$extIsFunction = true;
expect(true).toBeTruthy();
});
it('should be created even if 3rd party property has been set', function () {
var svg = d3.select('#chart svg');
expect(svg).not.toBeNull();
});
it('should have same width', function () {
var svg = d3.select('#chart svg');
expect(+svg.attr('width')).toBe(640);
}); });
it('should have same height', function () { describe('size', function () {
var svg = d3.select('#chart svg');
expect(+svg.attr('height')).toBe(480); it('should have same width', function () {
var svg = d3.select('#chart svg');
expect(+svg.attr('width')).toBe(640);
});
it('should have same height', function () {
var svg = d3.select('#chart svg');
expect(+svg.attr('height')).toBe(480);
});
}); });
}); });
...@@ -9,12 +9,12 @@ function Chart(config) { ...@@ -9,12 +9,12 @@ function Chart(config) {
// bind "this" to nested API // bind "this" to nested API
(function bindThis(fn, target, argThis) { (function bindThis(fn, target, argThis) {
for (var key in fn) { Object.keys(fn).forEach(function (key) {
target[key] = fn[key].bind(argThis); target[key] = fn[key].bind(argThis);
if (Object.keys(fn[key]).length > 0) { if (Object.keys(fn[key]).length > 0) {
bindThis(fn[key], target[key], argThis); bindThis(fn[key], target[key], argThis);
} }
} });
})(c3_chart_fn, this, this); })(c3_chart_fn, this, this);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment