Get help with testing, discuss unit testing strategies etc.


Post by jflowers45 »

I'm trying to figure out if it's possible to use 'desc' with 'waitFor'. I've tried a few variations but no luck so far. Is there a supported syntax?

attempt 1
 t.waitFor({
          desc: "testing",
          method: function() { 
            return (a == b);
          },
          callback: function() { next(); },
        });
attempt 2
{ waitFor: function() { return a == b }, desc:"sup"}
Any ideas? thanks.

Post by nickolay »

In the 1st form (method call) supported as "description" property instead of "desc" (i've updated the docs).
The 2nd form worked for me as is.

Post by jflowers45 »

You're right, the second example works. I messed it up in the actual implementation in my code.

Thanks for the clarification on "description" vs "desc" on the first.

Post by jflowers45 »

Hi Nikolay,

I'm unable to get the first example to work using 'description' as you mentioned.
StartTest(function(t) {
    t.chain(
      function(next) {
          t.waitFor({
            description: "this never prints",
            method: function() { 
              return (1 == 1);
            },
            callback: next,
        });
      },

      function(next) {
        t.pass("But this does print");
        next();
      }
    );
});

Post by nickolay »

Hi,

This is because we don't output anything from the "waitFor" if waiting took 0ms (successful first check, callback is called synchronously). This will output the descriptions for example:
StartTest(function(t) {
    var counter = 0

    t.chain(
        function(next) {
            t.waitFor({
                description: "this never prints",
                method: function() {
                    return counter++ == 5
                },
                callback: next,
            });
        },

        function(next) {
            t.pass("But this does print");
            next();
        }
    );
});
This was done this way because in some tests there were a lot of noise from such "empty" waits. We can add, that assertion should always be added if "description" property is provided, if you need this.

Post by jflowers45 »

Oh I see!

I personally think that if a user took the time to write a description, it's confusing if it doesn't show up - however, now that I know about it I can work around it, so I'd do whatever you think makes the most sense.

Thanks as always for quick response!

Post Reply