最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use SpyOnEvent to spy on events with jquery-jasmine - Stack Overflow

programmeradmin1浏览0评论

I'm using the jQuery-Jasmine extension to spy on events but i can't get the correct syntax.

// 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

but i clicked it on the row before the check so i must be doing something wrong.

I'm using the jQuery-Jasmine extension to spy on events but i can't get the correct syntax.

// 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

but i clicked it on the row before the check so i must be doing something wrong.

Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Jun 9, 2012 at 14:54 Nicola PeluchettiNicola Peluchetti 76.9k32 gold badges149 silver badges195 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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' ) );
} );
发布评论

评论列表(0)

  1. 暂无评论