d3.js - jasmine testing on external library -
i attempting basic testing using jasmine. use external library & intend spy/mock method calls on library object (d3) , make sure appropriate methods called on d3.
var d3spy = jasmine.createspyobj('d3', ['select']); spyon(window, 'd3').andreturn(d3spy); expect(d3spy.select).tohavebeencalled(); when 'select' being called on object, error.
typeerror: object function () { spyobj.wascalled = true; spyobj.callcount++; var args = jasmine.util.argstoarray(arguments); spyobj.mostrecentcall.object = this; spyobj.mostrecentcall.args = args; spyobj.argsforcall.push(args); spyobj.calls.push({object: this, args: args}); return spyobj.plan.apply(this, arguments); } has no method 'select' what doing wrong?
the failure in code following
spyon(window, 'd3').andreturn(d3spy); this line wil return spy when call d3(). replace d3 object function when called returns {select: jasmine.createspy()}. using d3 never call d3() cause select static member of d3
so solution spy on `d3.select'
spyon(d3, 'select') btw. problem libs d3 use heavy chaining is, hard mock. select spy in example has return object fits d3 selections object , on. easier not mock out everything.
Comments
Post a Comment