Files
DefinitelyTyped/types/d3-dispatch/d3-dispatch-tests.ts
Tom Wanzek 8ae97451d5 D3 Modules Linting (#16536)
* [d3-collection] Linted
* Added and completed linting
* Replaced `Object` with `any` adding TODO to change to proper `object` type when publishing the definitions to use TS 2.2+

* [d3-color] Linted

* [d3-dispatch] Linted

* [d3-hsv]  Linted

* [d3-interpolate] Linted. `Object` to `any`
* Replace use of `Object` as extension basis with `any` for now. Added TODO to change it to use the `object` type, when updating the definitions to formally use TS2.2+

* [d3-path] Linted.

* [d3-polygon] Linted.

* [d3-quadtree] Linted.

* [d3-queue] Linted.

* [d3-request] Linted.

* [d3-scale-chromatic] Linted.

* [d3-time-format] Linted.

* [d3-time] Linted.

* [d3-timer] Linted.

* [d3-voronoi] Linted.

* [d3-scale] Move callable-type lint deactivation to tslint.json
* line level deactivation was ignored.
2017-05-19 07:13:46 -07:00

55 lines
1.6 KiB
TypeScript

/**
* Typescript definition tests for d3/d3-dispatch module
*
* Note: These tests are intended to test the definitions only
* in the sense of typing and call signature consistency. They
* are not intended as functional tests.
*/
import * as d3Dispatch from 'd3-dispatch';
// Preparation --------------------------------------------
interface Datum {
a: number;
b: string;
}
let dispatch: d3Dispatch.Dispatch<HTMLElement>;
let copy: d3Dispatch.Dispatch<HTMLElement>;
let copy2: d3Dispatch.Dispatch<SVGElement>;
// Signature Tests ----------------------------------------
// create new dispatch object
dispatch = d3Dispatch.dispatch('foo', 'bar');
function cbFn(this: HTMLElement, d: Datum, i: number) {
console.log(this.baseURI ? this.baseURI : 'nada');
console.log(d ? d.a : 'nada');
}
function cbFn2(this: SVGElement, d: Datum, i: number) {
console.log(this.baseURI ? this.baseURI : 'nada');
console.log(d ? d.a : 'nada');
}
dispatch.on('foo', cbFn);
// dispatch.on('foo', cbFn2); // test fails as 'this' context type is mismatched between dispatch and callback function
dispatch.on('bar', dispatch.on('bar'));
dispatch.call('foo');
dispatch.call('foo', document.body);
dispatch.call('foo', document.body, { a: 3, b: 'test' }, 1);
dispatch.apply('bar');
dispatch.apply('bar', document.body);
dispatch.apply('bar', document.body, [{ a: 3, b: 'test' }, 1]);
dispatch.on('bar', null);
// Copy dispatch -----------------------------------------------
copy = dispatch.copy();
// copy2 = dispatch.copy(); // test fails type mismatch of underlying event target