mmonteleone/pavlov

asyncIt Feature Request

Closed this issue · 1 comments

I really like your library, but the one thing that hangs me up is async testing. The timeout wait you have works, but it can dramatically increase the time for the whole test suite to run.

There is another library like yours called SpecIt that has a asyncIt() method you can use instead of the it() which is just a small wrapper around QUnit's native asyncTest() method.

https://github.com/joshuaclayton/specit/blob/master/specit.js#L28

I think this addition would be very handy. Have you already considered this or are you thinking along a different lines?

Thank you for your feedback Elijah. Sorry it's taken me a couple weeks, but I've considered your async suggestion and, along with lots of other refactoring in Pavlov, I've included some initial async support.

I like the notion of asyncTest, but I wasn't crazy about asyncIt. It just seemed to collide with the grammar of BDD. There's "It should do foo", "It should do bar". But "AsyncIt should do foobar" seems strange. On the other hand, "It should do foobar asynchronously" seems rather nice, and describes exactly what's being tested.

So, I've rolled it in as a wrapper for the test's implementation:

it("should do foobar", async(function(){
    setTimeout(function(){
        assert.pass();
        resume();
    }, 500);
}));

And then in the output, it appends " asynchronously", i.e. "It should do foobar asynchronously". I've also added first class pause() and resume() methods available from within tests as well, which just proxy to stop() and start().

What do you think of this approach?

Unrelated, but I've also refactored the rest of Pavlov to no longer be QUnit-dependent. It's now sort of a "precompiler" which targets a minimal adapter interface, targeting a QUnit adapter by default. Ideally, there will be adapters available for other frameworks, and potentially node.js frameworks as well.

This work is all checked in and a documentation update is forthcoming.