aboutsummaryrefslogtreecommitdiff
path: root/js/tests/unit/tests-polyfills.js
blob: 4f2583e0db6071f27c66518f8e79ded90521f57d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Polyfills for our unit tests
(function () {
  'use strict'

  // Event constructor shim
  if (!window.Event || typeof window.Event !== 'function') {
    var origEvent = window.Event
    window.Event = function (inType, params) {
      params = params || {}
      var e = document.createEvent('Event')
      e.initEvent(inType, Boolean(params.bubbles), Boolean(params.cancelable))
      return e
    }

    window.Event.prototype = origEvent.prototype
  }

  if (typeof window.CustomEvent !== 'function') {
    window.CustomEvent = function (event, params) {
      params = params || { bubbles: false, cancelable: false, detail: null }
      var evt = document.createEvent('CustomEvent')
      evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail)
      return evt
    }

    CustomEvent.prototype = window.Event.prototype
  }
})()