source: trip-planner-front/node_modules/events/tests/special-event-names.js@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 1.4 KB
RevLine 
[6a3a178]1'use strict';
2
3var common = require('./common');
4var EventEmitter = require('../');
5var assert = require('assert');
6
7var ee = new EventEmitter();
8var handler = function() {};
9
10assert.strictEqual(ee.eventNames().length, 0);
11
12assert.strictEqual(ee._events.hasOwnProperty, undefined);
13assert.strictEqual(ee._events.toString, undefined);
14
15ee.on('__defineGetter__', handler);
16ee.on('toString', handler);
17ee.on('__proto__', handler);
18
19assert.strictEqual(ee.eventNames()[0], '__defineGetter__');
20assert.strictEqual(ee.eventNames()[1], 'toString');
21
22assert.strictEqual(ee.listeners('__defineGetter__').length, 1);
23assert.strictEqual(ee.listeners('__defineGetter__')[0], handler);
24assert.strictEqual(ee.listeners('toString').length, 1);
25assert.strictEqual(ee.listeners('toString')[0], handler);
26
27// Only run __proto__ tests if that property can actually be set
28if ({ __proto__: 'ok' }.__proto__ === 'ok') {
29 assert.strictEqual(ee.eventNames().length, 3);
30 assert.strictEqual(ee.eventNames()[2], '__proto__');
31 assert.strictEqual(ee.listeners('__proto__').length, 1);
32 assert.strictEqual(ee.listeners('__proto__')[0], handler);
33
34 ee.on('__proto__', common.mustCall(function(val) {
35 assert.strictEqual(val, 1);
36 }));
37 ee.emit('__proto__', 1);
38
39 process.on('__proto__', common.mustCall(function(val) {
40 assert.strictEqual(val, 1);
41 }));
42 process.emit('__proto__', 1);
43} else {
44 console.log('# skipped __proto__')
45}
Note: See TracBrowser for help on using the repository browser.