Testing with promises

251 views
Skip to first unread message

Tomas Neme

unread,
May 18, 2013, 7:08:54 PM5/18/13
to moc...@googlegroups.com
I've been recommended in https://github.com/kriskowal/q/issues/291 to do this when testing with mocha:

it("should be 5", function (done) {
  def.promise.then(function (val) {
    assert(val === 5);
  })
  .then(done, done);
}

But with this code:

            promise.then(function(result) {
                result = result.split('\r\n')[1].split(' ');
                var file = result[2];
                file.should.include('black_id');
            }).then(done, done);


I get this error message:
Error: done() invoked with non-Error: AssertionError: expected '"/test/playlists/519806a27df7ccfb5000000b-e79b8863-9509-4f2a-bdc7-3c8751127074.xml"' to include 'black_id'

While the result's OK since the test actually failed, why is mocha not seeing an AssertionError as an Error? Is this normal?

--
"The whole of Japan is pure invention. There is no such country, there are no such people" --Oscar Wilde

|_|0|_|
|_|_|0|
|0|0|0|

(\__/)
(='.'=)This is Bunny. Copy and paste bunny
(")_(") to help him gain world domination.

Wil Moore

unread,
May 19, 2013, 12:23:09 AM5/19/13
to moc...@googlegroups.com
I believe this will help:

promise.then(function(result) {
  result = result.split('\r\n')[1].split(' ');
  var file = result[2];
  file.should.include('black_id');
  done;
}).fail(done); // NOTE: when .always() is an option, you don't need the .fail()
Reply all
Reply to author
Forward
0 new messages