diff --git a/spec/api/api.zoom-spec.js b/spec/api/api.zoom-spec.js index 0ab9f6fdb..1cc8020c2 100644 --- a/spec/api/api.zoom-spec.js +++ b/spec/api/api.zoom-spec.js @@ -11,6 +11,8 @@ describe("API zoom", function() { let chart; describe("zoom line chart #1", () => { + const spy = sinon.spy(); + before(() => { chart = util.generate({ data: { @@ -21,7 +23,8 @@ describe("API zoom", function() { ] }, zoom: { - enabled: true + enabled: true, + onzoom: spy } }); }); @@ -35,6 +38,10 @@ describe("API zoom", function() { expect(domain[0]).to.be.equal(target[0]); expect(domain[1]).to.be.equal(target[1]); + + // onzoom callback has been called? + expect(spy.called).to.be.true; + expect(spy.args[0][0]).to.be.deep.equal(target); }); it("should be zoomed properly again", () => { diff --git a/spec/interactions/zoom-spec.js b/spec/interactions/zoom-spec.js index fe7ddf029..80fb18453 100644 --- a/spec/interactions/zoom-spec.js +++ b/spec/interactions/zoom-spec.js @@ -123,6 +123,8 @@ describe("ZOOM", function() { return new Promise((resolve, reject) => { setTimeout(() => { if (spyOnZoomStart.called) { + expect(spyOnZoomStart.args[0][0].type).to.be.equal("mousedown"); + util.fireEvent(eventRect, "mousemove", { clientX: 100, clientY: 150 @@ -138,17 +140,17 @@ describe("ZOOM", function() { return new Promise((resolve, reject) => { setTimeout(() => { if (spyOnZoom.called) { - if (spyOnZoom.called) { - util.fireEvent(eventRect, "mouseup", { - clientX: 100, - clientY: 150 - }, chart); + expect(spyOnZoom.args[0][0]).to.be.deep.equal([0, 3]); + + util.fireEvent(eventRect, "mouseup", { + clientX: 100, + clientY: 150 + }, chart); - // call explicitly, due to mouseup isn't firing well programmatically. - chart.internal.onZoomEnd(); + // call explicitly, due to mouseup isn't firing well programmatically. + chart.internal.onZoomEnd(); - resolve("--> onzoom callback called!"); - } + resolve("--> onzoom callback called!"); }; }, 500); }) diff --git a/src/api/api.zoom.js b/src/api/api.zoom.js index 916358605..aa217acda 100644 --- a/src/api/api.zoom.js +++ b/src/api/api.zoom.js @@ -70,7 +70,7 @@ const zoom = function(domainValue) { }); $$.setZoomResetButton(); - callFn($$.config.zoom_onzoom, resultDomain); + callFn($$.config.zoom_onzoom, $$.api, resultDomain); } else { resultDomain = $$.zoomScale ? $$.zoomScale.domain() : $$.x.orgDomain();