Automattic / expect.js

Minimalistic BDD-style assertions for Node.JS and the browser.
2.11k stars 209 forks source link

Promised support? #98

Closed truongsinh closed 10 years ago

truongsinh commented 10 years ago

Heavily inspired by chai-as-promised Instead of manually wiring up your expectations to a promise's fulfilled and rejected handlers:

doSumAsync(2, 2).then(
    function (result) {
        expect(result).be(4);
        done();
    },
    function (err) {
       done(err);
    }
);

you can write code that expresses what you really mean:

expect.promise(doSumAsync(2, 2).be(4).notify(done);

or if you have a testing framework that follows the UncommonJS specification for handling promises, simply

return expect.promise(doSumAsync(2, 2).be(4);

Do you think this feature should be in core, an extension, or a fork? And what about the api, should we use expect.promise(myPromise), or expect(myPromise) and expect checks duck-type for thenable.

Btw, I can work on this and make PR

rauchg commented 10 years ago

I think this would add a lot of complexity to the codebase, and ultimately be too magical and confusing for a testing library.