خرید بک لینک

Vote count: 0

I've got a unit test that triggers a keydown event. After the event is trigger another function is called. However, according to my test results this function is never called. From what I can tell the event is never actually getting triggered. Here's the method I'm testing:

 Wysiwyg.prototype.bindHotkeys = function( editor, options, toolbarBtnSelector ) {
    var self = this;
    $.each( options.hotKeys, function( hotkey, command ) {
        $( editor ).keydown( hotkey, function( e ) {
            if ( editor.attr( "contenteditable" ) && $( editor ).is( ":visible" ) ) {
                e.preventDefault();
                e.stopPropagation();
                self.execCommand( command, null, editor, options, toolbarBtnSelector );
            }
        } ).keyup( hotkey, function( e ) {
            if ( editor.attr( "contenteditable" ) && $( editor ).is( ":visible" ) ) {
                e.preventDefault();
                e.stopPropagation();
            }
        } );
    } );

and here is my unit test:

QUnit.test( "Wysiwyg#bindHotkeys() binding multiple events, multiple listeners called", function( assert ) {
    // Setup the test dependencies
    assert.expect( 6 );

    var wysiwyg = new window.Wysiwyg();
    var editor = $("<div></div>").attr( "contenteditable", true ).css("visibility", "visible");
    var options = {
        hotKeys: {
            "Ctrl+b meta+b": "bold",
            "Ctrl+i meta+i": "italic",
            "Ctrl+u meta+u": "underline",
            "Ctrl+z": "undo",
            "Ctrl+y meta+y meta+shift+z": "redo",
            "Ctrl+l meta+l": "justifyleft",
            "Ctrl+r meta+r": "justifyright",
            "Ctrl+e meta+e": "justifycenter",
            "Ctrl+j meta+j": "justifyfull",
            "Shift+tab": "outdent",
            "tab": "indent"
        },
        toolbarSelector: "[data-role=editor-toolbar]",
        commandRole: "edit",
        activeToolbarClass: "btn-info",
        selectionMarker: "edit-focus-marker",
        selectionColor: "darkgrey",
        dragAndDropImages: true,
        keypressTimeout: 200,
        fileUploadError: function( reason, detail ) { console.log( "File upload error", reason, detail ); }
    };

    sinon.stub(wysiwyg, "execCommand");

    // Manually trigger the keydown event
    var keydownEvent = jQuery.Event("keydown");
    keydownEvent.which = 72;
    keydownEvent.ctrlKey = true;
    $( editor ).trigger( keydownEvent );

    // Call the method we want to test
    wysiwyg.bindHotkeys( editor, options);

    // Verify the methods were called
    assert.ok( wysiwyg.execCommand.calledOnce, "wysiwyg.execComand() was called" );
});

Am I missing something in how I'm setting up my keydown event?

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 1 ارديبهشت 1395 ساعت: 10:06

صفحه بندی