# Code coverage report for modules/__tests__/CompositeDisposable-test.js

## Statements: 100% (97 / 97) Branches: 75% (3 / 4) Functions: 100% (21 / 21) Lines: 100% (96 / 96) Ignored: none

All files » modules/__tests__/ » CompositeDisposable-test.js

    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
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139

    3

    1

    1

    1

    1

    1

    1

    1
    1
    1
    1

    1
    10
    9

    10
    6

    10
    4

    1
    1
    1

    1
    1

    1
    1

    1
    1

    1
    1

    1
    1
    1
    1
    1

    1
    1
    1

    1
    1
    1
    1

    1
    1
    1
    1
    1
    1
    1
    1

    1
    1
    1
    1
    1
    1
    1
    1
    1
    1

    1
    1
    1
    1
    1
    1
    1

    1
    1
    1
    1
    1
    1
    1
    1

    1
    1
    1
    1
    1
    1

    1
    1
    1
    1
    1
    1
    1
    1

    1
    1
    1
    1

    1
    1
    1
    1

     'use strict';

    var _interopRequireWildcard = function (obj) { return obj && obj.__esModule ? obj : { 'default': obj }; };

    var _expect = require('expect.js');

    var _expect2 = _interopRequireWildcard(_expect);

    var _Disposable = require('../Disposable');

    var _Disposable2 = _interopRequireWildcard(_Disposable);

    var _CompositeDisposable = require('../CompositeDisposable');

    var _CompositeDisposable2 = _interopRequireWildcard(_CompositeDisposable);

    describe('CompositeDisposable', function () {
      var dispA = undefined;
      var dispB = undefined;
      var dispC = undefined;

      beforeEach(function () {
        dispA = new _Disposable2['default'](function () {
          dispA.disposed = true;
        });
        dispB = new _Disposable2['default'](function () {
          dispB.disposed = true;
        });
        dispC = new _Disposable2['default'](function () {
          dispC.disposed = true;
        });
      });

      it('accepts an array of or spread disposables', function () {
        _expect2['default'](function () {
          return new _CompositeDisposable2['default'](dispA);
        }).to.not.throwError();
        _expect2['default'](function () {
          return new _CompositeDisposable2['default'](dispA, dispB, dispC);
        }).to.not.throwError();
        _expect2['default'](function () {
          return new _CompositeDisposable2['default']([dispA, dispB, dispC]);
        }).to.not.throwError();
        _expect2['default'](function () {
          return new _CompositeDisposable2['default'](dispA, [dispA, dispB, dispC]);
        }).to.throwError();
        _expect2['default'](function () {
          return new _CompositeDisposable2['default']([dispA, dispB, dispC], dispA);
        }).to.throwError();
      });

      it('disposes children', function () {
        var composite = new _CompositeDisposable2['default'](dispA, dispB);
        composite.dispose();
        _expect2['default'](dispA.disposed).to.equal(true);
        _expect2['default'](dispB.disposed).to.equal(true);
      });

      it('does not attempt to dispose children twice', function () {
        var composite = new _CompositeDisposable2['default'](dispA, dispB);
        composite.dispose();

        dispA.disposed = dispB.disposed = 42;
        composite.dispose();
        _expect2['default'](dispA.disposed).to.equal(42);
        _expect2['default'](dispB.disposed).to.equal(42);
      });

      it('disposes newly added disposables like other children', function () {
        var composite = new _CompositeDisposable2['default'](dispA);
        composite.add(dispB);
        composite.add(dispC);
        composite.dispose();
        _expect2['default'](dispA.disposed).to.equal(true);
        _expect2['default'](dispB.disposed).to.equal(true);
        _expect2['default'](dispC.disposed).to.equal(true);
      });

      it('disposes removed children immediately', function () {
        var composite = new _CompositeDisposable2['default'](dispA);
        composite.add(dispB);
        composite.add(dispC);
        composite.remove(dispA);
        _expect2['default'](dispA.disposed).to.equal(true);
        composite.remove(dispC);
        _expect2['default'](dispC.disposed).to.equal(true);
        composite.dispose();
        _expect2['default'](dispB.disposed).to.equal(true);
      });

      it('treats same instances as different disposables when adding', function () {
        var composite = new _CompositeDisposable2['default'](dispA);
        composite.add(dispA);
        composite.add(dispA);
        composite.remove(dispA);
        composite.dispose();
        _expect2['default'](dispA.disposed).to.equal(true);
      });

      it('treats same instances as different disposables when removing', function () {
        var composite = new _CompositeDisposable2['default'](dispA);
        composite.add(dispA);
        _expect2['default'](composite.remove(dispA)).to.equal(true);
        _expect2['default'](dispA.disposed).to.equal(true);
        _expect2['default'](composite.remove(dispA)).to.equal(true);
        _expect2['default'](composite.remove(dispA)).to.equal(false);
        composite.dispose();
      });

      it('ignores remove for a non-existant child', function () {
        var composite = new _CompositeDisposable2['default'](dispA);
        _expect2['default'](composite.remove(dispB)).to.equal(false);
        composite.dispose();
        _expect2['default'](dispA.disposed).to.equal(true);
        _expect2['default'](dispB.disposed).to.equal(undefined);
      });

      it('disposes newly added disposables immediately if disposed itself', function () {
        var composite = new _CompositeDisposable2['default'](dispA);
        composite.dispose();
        _expect2['default'](dispA.disposed).to.equal(true);
        composite.add(dispB);
        _expect2['default'](dispB.disposed).to.equal(true);
        composite.add(dispC);
        _expect2['default'](dispC.disposed).to.equal(true);
      });

      it('does not store children if disposed itself', function () {
        var composite = new _CompositeDisposable2['default'](dispA);
        composite.add(dispB);
        composite.dispose();

        _expect2['default'](composite.remove(dispA)).to.equal(false);
        _expect2['default'](composite.remove(dispB)).to.equal(false);
        composite.add(dispC);
        _expect2['default'](composite.remove(dispC)).to.equal(false);
      });
    });
    //# sourceMappingURL=data:application/json;base64,[encoded data, 11752 characters]