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

## Statements: 100% (75 / 75) Branches: 75% (3 / 4) Functions: 100% (16 / 16) Lines: 100% (74 / 74) Ignored: none

All files » modules/__tests__/ » SerialDisposable-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

    3

    1

    1

    1

    1

    1

    1

    1
    1
    1
    1

    1
    6
    5

    6
    2

    6
    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 _SerialDisposable = require('../SerialDisposable');

    var _SerialDisposable2 = _interopRequireWildcard(_SerialDisposable);

    describe('SerialDisposable', 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('throws on bad disposable', function () {
        var serial = new _SerialDisposable2['default']();
        _expect2['default'](function () {
          return serial.setDisposable(42);
        }).to.throwError();
        _expect2['default'](function () {
          return serial.setDisposable({});
        }).to.throwError();
        _expect2['default'](function () {
          return serial.setDisposable(0);
        }).to.throwError();
        _expect2['default'](function () {
          return serial.setDisposable('');
        }).to.throwError();
      });

      it('lets you get and set the current disposable', function () {
        var serial = new _SerialDisposable2['default']();
        _expect2['default'](serial.getDisposable()).equal(null);
        serial.setDisposable(dispA);
        _expect2['default'](serial.getDisposable()).equal(dispA);
        serial.setDisposable(null);
        _expect2['default'](serial.getDisposable()).equal(null);
        serial.setDisposable();
        _expect2['default'](serial.getDisposable()).equal(null);
        serial.setDisposable(dispA);
        _expect2['default'](serial.getDisposable()).equal(dispA);
      });

      it('disposes the current disposable on own dispose', function () {
        var serial = new _SerialDisposable2['default']();
        serial.setDisposable(dispA);
        _expect2['default'](dispA.disposed).to.equal(undefined);
        serial.dispose();
        _expect2['default'](dispA.disposed).to.equal(true);
      });

      it('disposes the just current disposable if is disposed itself', function () {
        var serial = new _SerialDisposable2['default']();
        serial.dispose();
        serial.setDisposable(dispA);
        _expect2['default'](dispA.disposed).to.equal(true);
        serial.setDisposable(null);
        serial.setDisposable(dispB);
        _expect2['default'](dispB.disposed).to.equal(true);
      });

      it('disposes the previous disposable ', function () {
        var serial = new _SerialDisposable2['default']();
        serial.setDisposable(dispA);
        _expect2['default'](dispA.disposed).to.equal(undefined);
        serial.setDisposable(dispB);
        _expect2['default'](dispA.disposed).to.equal(true);
        _expect2['default'](dispB.disposed).to.equal(undefined);
        serial.setDisposable(null);
        _expect2['default'](dispB.disposed).to.equal(true);
        serial.setDisposable(dispC);
        _expect2['default'](dispC.disposed).to.equal(undefined);
        serial.setDisposable(null);
        _expect2['default'](dispC.disposed).to.equal(true);
      });

      it('does not attempt to dispose the child twice', function () {
        var serial = new _SerialDisposable2['default']();
        serial.setDisposable(dispA);
        serial.dispose();
        _expect2['default'](dispA.disposed).to.equal(true);

        dispA.disposed = 42;
        serial.dispose();
        _expect2['default'](dispA.disposed).to.equal(42);
      });
    });
    //# sourceMappingURL=data:application/json;base64,[encoded data, 8248 characters]