d3.jsライブラリを使用している角型アプリケーションでチャート指示文があります。ディレクティブのd3.js - svg要素のクリックを呼び出すjasmineテスト
パートがとても
svg.selectAll('g rect')
.on('click', function(d) {
scope.clickHandler(d, scope.data);
})
.on('mouseover', function() {
d3.select(this).classed('data-item-hover', true);
})
.on('mouseout', function() {
d3.select(this).classed('data-item-hover', false);
});
のようないくつかのSVG要素にマウスイベントハンドラを追加し、私はいくつかのユニットテストではこれらのハンドラをカバーしたいが、実際に動的にこれらのイベントを起動する方法に苦しんでいます。
私は、しかし、これは私がこのSO How to invoke "click" event programmatically in d3?出くわしと第二の答えは、この技術を試しに私を導いたものであるエラー
TypeError: undefined is not a constructor (evaluating 'rect.on('click')'
を投げる私のテスト仕様
describe('scope.clickHandler', function() {
var rect;
beforeEach(function(){
spyOn(scope, 'clickHandler');
rect = svg.select('g rect')[0][0];
rect.on('click')();
});
it('should call scope.render after a window resize event occurs', function() {
expect(scope.clickHandler).toHaveBeenCalled();
});
});
でこれをしようとしています。
d3.jsでイベントを登録したsvg要素でマウスイベントを呼び出すにはどうすればよいですか?
おかげ
http://stackoverflow.com/questions/9063383/how-to-invoke-click-event-programmatically-in-d3 – jarandaf
これは私の質問の一番下に参照した正確なリンクです – mindparse
私の悪い:) svg.select( 'g rect')[0] [0] 'はDOM要素ですが、d3は選択配列自体にメソッドをバインドします。したがって、エラー – jarandaf