【问题标题】:How to use SpyOnEvent to spy on events with jquery-jasmine如何使用 SpyOnEvent 通过 jquery-jasmine 监视事件
【发布时间】:2012-06-13 06:55:47
【问题描述】:

我正在使用jQuery-Jasmine 扩展来监视事件,但我无法获得正确的语法。

// Get a button
var $button = $( '#ai1ec_subscribe_users' );
// Call the function
utility_functions.block_all_submit_and_ajax( $button.get(0) );
// check that all submit are disabled
var first_multi = $( '.ai1ec-facebook-refresh-multiselect:first' );
spyOnEvent( '.ai1ec-facebook-refresh-multiselect:first', 'click' );
first_multi.click();
expect( 'click' ).toHaveBeenTriggeredOn( '.ai1ec-facebook-refresh-multiselect:first' );

这让我回来了

预期事件点击已被触发 .ai1ec-facebook-refresh-multiselect:first

但我在检查前点击了它,所以我一定做错了什么。

【问题讨论】:

    标签: javascript jquery unit-testing jasmine jasmine-jquery


    【解决方案1】:

    问题是我没有以正确的方式触发事件。

    这行得通:

    it( "Prevent all ajax functionality", function() {
            // Get a button
            var $button = $( '#ai1ec_subscribe_users' );
            // Call the function
            utility_functions.block_all_submit_and_ajax( $button.get(0) );
            // check that all submit are disabled
            spyOnEvent( $( '.ai1ec-facebook-refresh-multiselect:first' ), 'click' );
            $( '.ai1ec-facebook-refresh-multiselect:first' )[0].click();
            expect( 'click' ).toHaveBeenTriggeredOn( $( '.ai1ec-facebook-refresh-multiselect:first' ) );
    } );
    

    【讨论】:

      猜你喜欢
      • 2016-01-13
      • 2011-06-07
      • 1970-01-01
      • 2016-03-10
      • 2013-11-07
      • 1970-01-01
      • 2013-01-09
      • 2011-07-17
      相关资源
      最近更新 更多