Improve tests, pass index to defined().

Had to modify d3.d.ts; will submit PR to DefinitelyTyped.