Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assume.wait but immediately calls next on failure #14

Open
terinjokes opened this issue Feb 9, 2016 · 0 comments
Open

assume.wait but immediately calls next on failure #14

terinjokes opened this issue Feb 9, 2016 · 0 comments

Comments

@terinjokes
Copy link
Contributor

This might be better served by a try/catch wrapper, or something like tryit, but wanted to get feedback.

The assume.wait function is supposed to make it much similar to handle async tests. However, it's still a bit annoy to remember to capture errors to be able to pass them to next. For example:

 it('does async things', function (done) {
   next = assume.wait(2, 4, done);

   asynctask(function (err, data) {
     assume(err).is.a('undefined');
     assume(data).equals('testing');

     next();
   });

   asynctaskfail(function (err, data) {
     assume(err).is.a('undefined');
     assume(data).equals('testing');

     next();
   });
 });

If asynctaskfail actually did return an err, one might expect done to be called with the assertion error. Instead nothing happens, and most harnesses will time out after 2 seconds, giving the user the harness's timeout error instead.

To handle this correctly, I must write something similar to the following:

 it('does async things', function (done) {
   next = assume.wait(2, 4, done);

   asynctask(function (err, data) {
     try {
       assume(err).is.a('undefined');
       assume(data).equals('testing');

       next();
     } catch(e) {
       next(e);
     }
   });

   asynctaskfail(function (err, data) {
     try {
       assume(err).is.a('undefined');
       assume(data).equals('testing');

       next();
     } catch(e) {
       next(e);
     }
   });
 });

This isn't much different than the code I had to write before assume.wait, so I'm not sure what benefit it brings to the table in the current iteration.

While reading the documentation and glancing at the example, I expected the assertion functions to immediately call done on error, instead of throwing an exception.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant