Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
make real events happen in-browser, with pure DOM and optional $
branch: master

Add bower

latest commit cf9e4fc827
Tom MacWright authored

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




With component

component install tmcw/happen

With Browserify

npm install happen

var happen = require('happen');

With bower

bower install tmcw/happen

Native API


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
var element = document.getElementById('map');

// click shortcut;

// dblclick shortcut

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

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

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

jQuery Plugin

// Shortcut - 'click' is shorthand for { type: 'click' }

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

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


  • 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

Something went wrong with that request. Please try again.