summaryrefslogtreecommitdiff
path: root/spec/javascripts/lib/utils/custom_event_polyfill_spec.js.es6
blob: 3645dd70c55876c4c2d65ca9d09e0578dfe66cc2 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//= require lib/utils/custom_event_polyfill

describe('Custom Event Polyfill', () => {
  it('should be defined', () => {
    expect(window.CustomEvent).toBeDefined();
  });

  it('should create a `CustomEvent` instance', () => {
    const e = new window.CustomEvent('foo');

    expect(e.type).toEqual('foo');
    expect(e.bubbles).toBe(false);
    expect(e.cancelable).toBe(false);
    expect(e.detail).toBeFalsy();
  });

  it('should create a `CustomEvent` instance with a `details` object', () => {
    const e = new window.CustomEvent('bar', { detail: { foo: 'bar' } });

    expect(e.type).toEqual('bar');
    expect(e.bubbles).toBe(false);
    expect(e.cancelable).toBe(false);
    expect(e.detail.foo).toEqual('bar');
  });

  it('should create a `CustomEvent` instance with a `bubbles` boolean', () => {
    const e = new window.CustomEvent('bar', { bubbles: true });

    expect(e.type).toEqual('bar');
    expect(e.bubbles).toBe(true);
    expect(e.cancelable).toBe(false);
    expect(e.detail).toBeFalsy();
  });

  it('should create a `CustomEvent` instance with a `cancelable` boolean', () => {
    const e = new window.CustomEvent('bar', { cancelable: true });

    expect(e.type).toEqual('bar');
    expect(e.bubbles).toBe(false);
    expect(e.cancelable).toBe(true);
    expect(e.detail).toBeFalsy();
  });
});