tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

event-target.test.js (6889B)


      1 'use strict';
      2 
      3 const assert = require('assert');
      4 
      5 const {
      6  CloseEvent,
      7  ErrorEvent,
      8  Event,
      9  MessageEvent
     10 } = require('../lib/event-target');
     11 
     12 describe('Event', () => {
     13  describe('#ctor', () => {
     14    it('takes a `type` argument', () => {
     15      const event = new Event('foo');
     16 
     17      assert.strictEqual(event.type, 'foo');
     18    });
     19  });
     20 
     21  describe('Properties', () => {
     22    describe('`target`', () => {
     23      it('is enumerable and configurable', () => {
     24        const descriptor = Object.getOwnPropertyDescriptor(
     25          Event.prototype,
     26          'target'
     27        );
     28 
     29        assert.strictEqual(descriptor.configurable, true);
     30        assert.strictEqual(descriptor.enumerable, true);
     31        assert.ok(descriptor.get !== undefined);
     32        assert.ok(descriptor.set === undefined);
     33      });
     34 
     35      it('defaults to `null`', () => {
     36        const event = new Event('foo');
     37 
     38        assert.strictEqual(event.target, null);
     39      });
     40    });
     41 
     42    describe('`type`', () => {
     43      it('is enumerable and configurable', () => {
     44        const descriptor = Object.getOwnPropertyDescriptor(
     45          Event.prototype,
     46          'type'
     47        );
     48 
     49        assert.strictEqual(descriptor.configurable, true);
     50        assert.strictEqual(descriptor.enumerable, true);
     51        assert.ok(descriptor.get !== undefined);
     52        assert.ok(descriptor.set === undefined);
     53      });
     54    });
     55  });
     56 });
     57 
     58 describe('CloseEvent', () => {
     59  it('inherits from `Event`', () => {
     60    assert.ok(CloseEvent.prototype instanceof Event);
     61  });
     62 
     63  describe('#ctor', () => {
     64    it('takes a `type` argument', () => {
     65      const event = new CloseEvent('foo');
     66 
     67      assert.strictEqual(event.type, 'foo');
     68    });
     69 
     70    it('takes an optional `options` argument', () => {
     71      const event = new CloseEvent('close', {
     72        code: 1000,
     73        reason: 'foo',
     74        wasClean: true
     75      });
     76 
     77      assert.strictEqual(event.type, 'close');
     78      assert.strictEqual(event.code, 1000);
     79      assert.strictEqual(event.reason, 'foo');
     80      assert.strictEqual(event.wasClean, true);
     81    });
     82  });
     83 
     84  describe('Properties', () => {
     85    describe('`code`', () => {
     86      it('is enumerable and configurable', () => {
     87        const descriptor = Object.getOwnPropertyDescriptor(
     88          CloseEvent.prototype,
     89          'code'
     90        );
     91 
     92        assert.strictEqual(descriptor.configurable, true);
     93        assert.strictEqual(descriptor.enumerable, true);
     94        assert.ok(descriptor.get !== undefined);
     95        assert.ok(descriptor.set === undefined);
     96      });
     97 
     98      it('defaults to 0', () => {
     99        const event = new CloseEvent('close');
    100 
    101        assert.strictEqual(event.code, 0);
    102      });
    103    });
    104 
    105    describe('`reason`', () => {
    106      it('is enumerable and configurable', () => {
    107        const descriptor = Object.getOwnPropertyDescriptor(
    108          CloseEvent.prototype,
    109          'reason'
    110        );
    111 
    112        assert.strictEqual(descriptor.configurable, true);
    113        assert.strictEqual(descriptor.enumerable, true);
    114        assert.ok(descriptor.get !== undefined);
    115        assert.ok(descriptor.set === undefined);
    116      });
    117 
    118      it('defaults to an empty string', () => {
    119        const event = new CloseEvent('close');
    120 
    121        assert.strictEqual(event.reason, '');
    122      });
    123    });
    124 
    125    describe('`wasClean`', () => {
    126      it('is enumerable and configurable', () => {
    127        const descriptor = Object.getOwnPropertyDescriptor(
    128          CloseEvent.prototype,
    129          'wasClean'
    130        );
    131 
    132        assert.strictEqual(descriptor.configurable, true);
    133        assert.strictEqual(descriptor.enumerable, true);
    134        assert.ok(descriptor.get !== undefined);
    135        assert.ok(descriptor.set === undefined);
    136      });
    137 
    138      it('defaults to false', () => {
    139        const event = new CloseEvent('close');
    140 
    141        assert.strictEqual(event.wasClean, false);
    142      });
    143    });
    144  });
    145 });
    146 
    147 describe('ErrorEvent', () => {
    148  it('inherits from `Event`', () => {
    149    assert.ok(ErrorEvent.prototype instanceof Event);
    150  });
    151 
    152  describe('#ctor', () => {
    153    it('takes a `type` argument', () => {
    154      const event = new ErrorEvent('foo');
    155 
    156      assert.strictEqual(event.type, 'foo');
    157    });
    158 
    159    it('takes an optional `options` argument', () => {
    160      const error = new Error('Oops');
    161      const event = new ErrorEvent('error', { error, message: error.message });
    162 
    163      assert.strictEqual(event.type, 'error');
    164      assert.strictEqual(event.error, error);
    165      assert.strictEqual(event.message, error.message);
    166    });
    167  });
    168 
    169  describe('Properties', () => {
    170    describe('`error`', () => {
    171      it('is enumerable and configurable', () => {
    172        const descriptor = Object.getOwnPropertyDescriptor(
    173          ErrorEvent.prototype,
    174          'error'
    175        );
    176 
    177        assert.strictEqual(descriptor.configurable, true);
    178        assert.strictEqual(descriptor.enumerable, true);
    179        assert.ok(descriptor.get !== undefined);
    180        assert.ok(descriptor.set === undefined);
    181      });
    182 
    183      it('defaults to `null`', () => {
    184        const event = new ErrorEvent('error');
    185 
    186        assert.strictEqual(event.error, null);
    187      });
    188    });
    189 
    190    describe('`message`', () => {
    191      it('is enumerable and configurable', () => {
    192        const descriptor = Object.getOwnPropertyDescriptor(
    193          ErrorEvent.prototype,
    194          'message'
    195        );
    196 
    197        assert.strictEqual(descriptor.configurable, true);
    198        assert.strictEqual(descriptor.enumerable, true);
    199        assert.ok(descriptor.get !== undefined);
    200        assert.ok(descriptor.set === undefined);
    201      });
    202 
    203      it('defaults to an empty string', () => {
    204        const event = new ErrorEvent('error');
    205 
    206        assert.strictEqual(event.message, '');
    207      });
    208    });
    209  });
    210 });
    211 
    212 describe('MessageEvent', () => {
    213  it('inherits from `Event`', () => {
    214    assert.ok(MessageEvent.prototype instanceof Event);
    215  });
    216 
    217  describe('#ctor', () => {
    218    it('takes a `type` argument', () => {
    219      const event = new MessageEvent('foo');
    220 
    221      assert.strictEqual(event.type, 'foo');
    222    });
    223 
    224    it('takes an optional `options` argument', () => {
    225      const event = new MessageEvent('message', { data: 'bar' });
    226 
    227      assert.strictEqual(event.type, 'message');
    228      assert.strictEqual(event.data, 'bar');
    229    });
    230  });
    231 
    232  describe('Properties', () => {
    233    describe('`data`', () => {
    234      it('is enumerable and configurable', () => {
    235        const descriptor = Object.getOwnPropertyDescriptor(
    236          MessageEvent.prototype,
    237          'data'
    238        );
    239 
    240        assert.strictEqual(descriptor.configurable, true);
    241        assert.strictEqual(descriptor.enumerable, true);
    242        assert.ok(descriptor.get !== undefined);
    243        assert.ok(descriptor.set === undefined);
    244      });
    245 
    246      it('defaults to `null`', () => {
    247        const event = new MessageEvent('message');
    248 
    249        assert.strictEqual(event.data, null);
    250      });
    251    });
    252  });
    253 });