Example #1
0
  'test errback+callback from constructor': function (beforeExit) {
    var promise = new Promise(function (err) {
          err.should.be.an.instanceof(Error);
          called++;
        })
      , called = 0;

    promise.error(new Error('dawg'));

    beforeExit(function () {
      called.should.eql(1);
    });
  },
Example #2
0
  'test addErrback shortcut': function (beforeExit) {
    var promise = new Promise()
      , called = 0;

    promise.addErrback(function (err) {
      err.should.be.an.instanceof(Error);
      called++;
    });

    promise.error(new Error);

    beforeExit(function () {
      called.should.eql(1);
    });
  }
Example #3
0
  'test errback+callback after error()ing': function (beforeExit) {
    var promise = new Promise()
      , called = 0;
    
    promise.error(new Error('woot'));

    promise.addBack(function (err){
      err.should.be.an.instanceof(Error);
      called++;
    });

    promise.addBack(function (err){
      err.should.be.an.instanceof(Error);
      called++;
    });

    beforeExit(function () {
      called.should.eql(2);
    });
  },
Example #4
0
  'test that events fire right away after error()ing': function (beforeExit) {
    var promise = new Promise()
      , called = 0;

    promise.on('err', function (err) {
      err.should.be.an.instanceof(Error);
      called++;
    });

    promise.error(new Error('booyah'));

    promise.on('err', function (err) {
      err.should.be.an.instanceof(Error);
      called++;
    });

    beforeExit(function () {
      called.should.eql(2);
    });
  },