source: trip-planner-front/node_modules/custom-event/test/test.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.3 KB
Line 
1
2var assert = require('assert');
3var CE = require('../');
4
5describe('CustomEvent', function () {
6
7 describe('new CustomEvent()', function () {
8
9 it('should create a `CustomEvent` instance', function () {
10 var e = new CE('cat');
11
12 assert.equal(e.type, 'cat');
13 assert.equal(e.bubbles, false);
14 assert.equal(e.cancelable, false);
15 assert.equal(e.detail, undefined);
16 });
17
18 it('should create a `CustomEvent` instance with a `details` object', function () {
19 var e = new CE('meow', { detail: { foo: 'bar' } });
20
21 assert.equal(e.type, 'meow');
22 assert.equal(e.bubbles, false);
23 assert.equal(e.cancelable, false);
24 assert.equal(e.detail.foo, 'bar');
25 });
26
27 it('should create a `CustomEvent` instance with a `bubbles` boolean', function () {
28 var e = new CE('purr', { bubbles: true });
29
30 assert.equal(e.type, 'purr');
31 assert.equal(e.bubbles, true);
32 assert.equal(e.cancelable, false);
33 assert.equal(e.detail, undefined);
34 });
35
36 it('should create a `CustomEvent` instance with a `cancelable` boolean', function () {
37 var e = new CE('scratch', { cancelable: true });
38
39 assert.equal(e.type, 'scratch');
40 assert.equal(e.bubbles, false);
41 assert.equal(e.cancelable, true);
42 assert.equal(e.detail, undefined);
43 });
44
45 it('should create a `CustomEvent` instance that is dispatchable', function (done) {
46 var e = new CE('claw', {
47 bubbles: true,
48 cancelable: true,
49 detail: { canhaz: 'cheeseburger' }
50 });
51
52 function onclaw (ev) {
53 if (!ev) ev = window.event;
54 assert.equal(e.bubbles, true);
55 assert.equal(e.cancelable, true);
56 assert.equal(e.detail.canhaz, 'cheeseburger');
57 done();
58 }
59
60 if (document.body.dispatchEvent) {
61 document.body.addEventListener('claw', onclaw, false);
62 document.body.dispatchEvent(e);
63 } else {
64 // IE <= 8 will only allow us to fire "known" event names,
65 // so we need to fire "click" instead of "claw :\
66 document.body.attachEvent('onclick', onclaw);
67
68 // need to fire event in a separate tick for some reason…
69 setTimeout(function () {
70 e.type = 'click';
71 e.eventName = 'click';
72 e.eventType = 'click';
73
74 document.body.fireEvent('onclick', e);
75 }, 50);
76 }
77 });
78
79 });
80
81});
Note: See TracBrowser for help on using the repository browser.