Detalhes do pacote

happen

tmcw7.1kBSD-2-Clause0.3.2

real browser events

testing, browser

readme (leia-me)

Circle CI Greenkeeper badge

happen wraps the createEvent DOM API to make real event mocking in-browser palatable.

Installation

Raw:

wget https://raw.github.com/tmcw/happen/master/happen.js

With component

component install tmcw/happen

With Browserify

npm install happen

var happen = require('happen');

With bower

bower install tmcw/happen

Native API

once()

happen.once(element, options) fires an event once. The element must be a DOM element. options must have a type for event type, then can have options:

Keyboard Events

  • keyCode
  • charCode
  • shiftKey
  • metaKey
  • ctrlKey
  • altKey

Mouse Events

  • detail
  • screenX
  • screenY
  • clientX
  • clientY
  • ctrlKey
  • altKey
  • shiftKey
  • metaKey
  • button

Touch Events

  • touchstart
  • touchmove
  • touchend
var element = document.getElementById('map');

// click shortcut
happen.click(element);

// dblclick shortcut
happen.dblclick(element);

// custom options
happen.dblclick(element, { shift: true });

// any other event type under MouseEvents
happen.once(element, {
    type: 'mousewheel',
    detail: -100
});

// The once api takes
happen.once(
    // element
    element, {
        // event type (e.type)
        type: 'mousewheel',
        // any other options
        detail: -100
    });

// touch events
happen.once(element, {
        type : 'touchstart',
        touches : [{
                pageX : 800,
                pageY : 800
            },
            {
                pageX : 400,
                pageY : 400
            }]
    });

jQuery Plugin

// Shortcut - 'click' is shorthand for { type: 'click' }
$('.foo').happen('click');

// Longhand - specify any sort of properties
$('.foo').happen({ type: 'keyup', keyCode: 50 });

// Works on any jQuery selection
$('.foo, .bar').happen('dblclick');

Shortcuts:

  • happen.click
  • happen.dblclick
  • happen.mousedown
  • happen.mouseup
  • happen.mousemove
  • happen.keydown
  • happen.keyup
  • happen.keypress

Use it with a testing framework, like Jasmine or Mocha.

(IE tests failing due to Chai)

See Also

changelog (log de mudanças)

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.3.2 (2017-10-25)

Bug Fixes

  • Enable bubbling for DOM3 Event (8413443)

0.3.0

  • Added touch support: touchstart, touchmove, and touchend.

0.2.0

  • Add ability to define relatedTarget property of an event.

0.1.3

  • The 'clicks' parameter is now called 'detail' because it is used outside of just double-clicking.

0.1.2

  • Fixes keyboard events in Safari

0.1.1

  • Fixes naming of modifier keys

0.1.0

  • Add mouseover and mouseout events.

0.0.2

  • Fixed jQuery plugin inclusion - now works properly without jQuery available.