简体   繁体   English

如何使用SpyOnEvent监视jquery-jasmine事件

[英]How to use SpyOnEvent to spy on events with jquery-jasmine

I'm using the jQuery-Jasmine extension to spy on events but i can't get the correct syntax. 我正在使用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' );

This gives me back 这让我回来了

Expected event click to have been triggered on .ai1ec-facebook-refresh-multiselect:first 预期事件点击已在.ai1ec-facebook-refresh-multiselect上触发:首先

but i clicked it on the row before the check so i must be doing something wrong. 但我在检查前点击了它,所以我一定做错了。

The problem was that I wasn't triggering the event in the right way. 问题是我没有以正确的方式触发事件。

This worked: 这有效:

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' ) );
} );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM