All Downloads are FREE. Search and download functionalities are using the official Maven repository.

package.tests.unit.test_events.js Maven / Gradle / Ivy

The newest version!
module('eventEmitter');

test('test the eventemitter', function() {
    expect(6);

    var ee = new Hammer.Manager(utils.createHitArea());
    var inputData = {
        target: document.body,
        srcEvent: {
            preventDefault: function() {
                ok(true, 'preventDefault ref');
            },
            target: document.body
        }
    };

    function event3Handler() {
        ok(true, 'emitted event3');
    }

    ee.on('testEvent1', function() {
        ok(true, 'emitted event');
    });
    ee.on('testEvent2', function(ev) {
        ok(true, 'emitted event');
        ev.preventDefault();
        ok(ev.target === document.body, 'target is the body');
    });
    ee.on('testEvent3', event3Handler);

    ee.emit('testEvent1', inputData);
    ee.emit('testEvent2', inputData);
    ee.emit('testEvent3', inputData);

    // unbind testEvent2
    ee.off('testEvent2');
    ee.off('testEvent3', event3Handler);

    ee.emit('testEvent1', inputData); // should trigger testEvent1 again
    ee.emit('testEvent2', inputData); // doenst trigger a thing
    ee.emit('testEvent3', inputData); // doenst trigger a thing

    // destroy
    ee.destroy();

    ee.emit('testEvent1', inputData); // doenst trigger a thing
    ee.emit('testEvent2', inputData); // doenst trigger a thing
    ee.emit('testEvent3', inputData); // doenst trigger a thing
});

/*
 * Hammer.Manager.off method : exception handling
 */
test("When Hammer.Manager didn't attach an event, 'off' method is ignored", function() {
    var count = 0;
    hammer = new Hammer(el, { inputTarget: document.body });
    hammer.off("swipeleft", function(e) {
        count++;
    });
    ok(true, "nothing");
});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy