medikoo / deferred

Modular and fast Promises implementation for JavaScript
ISC License
364 stars 20 forks source link

usage with nodejs asserts #30

Closed SET001 closed 10 years ago

SET001 commented 10 years ago

How can this library be user with nodejs asserts (library for unit testing)? It seem's like it handle any exception inside promise callback so it is not possible to use assertions:

is_connected.promise ->
      console.log "resolved!"
      assert.equal 1, 2
      throw 'any error'
      done()
is_connected.resolve()

Writing tests in such a way I would never know about fails. How I can handle this?

SET001 commented 10 years ago

Sorry, I just have to read manual about error handling:

is_connected.promise ->
  console.log "resolved!"
  assert.equal 1, 2
  done()
.done()
is_connected.resolve()
medikoo commented 10 years ago

Exactly, and a bit cleaner would be:

isConnected.promise.done(function () {
  console.log("resolved!");
  assert.equal(1, 2);
  done();
});

isConnected.promise() is same as isConnected.promise.then() so it creates transformation promise, and implies unfortunate in that case error swallowing