Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gparlakov/20cc08d8da6b92baacb41d61a5c00cf7 to your computer and use it in GitHub Desktop.
Save gparlakov/20cc08d8da6b92baacb41d61a5c00cf7 to your computer and use it in GitHub Desktop.
test-chart-js.callback-calls-routre-method.ts
it('when clicked on the second point should navigate to show the selected point', () => {
// arrange
const r = mockRouter();
// arrange the onclick prerequisites
const ch = jasmine.createSpy('chart builder');
let onClickCallback: Function = () => {};
ch.and.callFake((i, o) => {
onClickCallback = o.options.onClick;
return {}; // <-- mock needed chart methods and props here
});
const c = new ChartComponent(r, ch);
c.canvas = new ElementRef(document.createElement('canvas'));
c.ngAfterViewInit();
// act
onClickCallback(null, [{ index: 1 }]);
// assert
expect(r.navigate).toHaveBeenCalledWith([2]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment