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
component
Withcomponent install tmcw/happen
With Browserify
npm install happen
var happen = require('happen');
bower
Withbower 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; // click shortcuthappen; // dblclick shortcuthappen; // custom optionshappen; // any other event type under MouseEventshappen; // The once api takeshappen; // touch eventshappen;
jQuery Plugin
// Shortcut - 'click' is shorthand for { type: 'click' }; // Longhand - specify any sort of properties; // Works on any jQuery selection;
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)