d3.chart [unit testing]: Spying on Chart Methods

46 visningar
Hoppa till det första olästa meddelandet

E Dana

oläst,
3 mars 2015 16:33:082015-03-03
till d3...@googlegroups.com
What is the best way to spy on a d3.chart method that is called during `initialize()`?

Context:
  • d3.chart library
  • Unit testing with mocha and sinon

The below code requires instantiating the grid twice:
Once to create the Grid instance on which the spy is created
Then a second time for the spied method to be recorded

The below code works, but I wonder if there is a better and cleaner way. 
*Code is based on the unit tests for d3.chart itself.


test("Calls `util.parse.options` with `options`", function() {
var gridSpy = this.gridSpy =
d3.select("#test").chart("Grid");

sinon.spy(gridSpy.deep.nested, "method");

this.grid = d3.select('#test')
.append('svg')
.chart(
'Grid', 
{ options: this.options }
);

assert.deepEqual(gridSpy.deep.nested.method.args[0][0], this.options);
});

Thanks,

-Evan
Svara alla
Svara författaren
Vidarebefordra
0 nya meddelanden