addAsync result doesn't preserve 'has 0 arguments' (.length == 0) #12

Open
Strilanc opened this Issue Mar 29, 2012 · 1 comment

Comments

Projects
None yet
2 participants

The result of the addAsync method is a function whose length is not 0, even if the input argument is 0. If a tested method expects a callback to take 0 arguments, and checks this fact, the addAsync method prevents the test from succeeding and has to be worked around:

    private function testableAwaitCallback(func : Function) : Function {
        var x:Function = this.addAsync(func);
        if (func.length > 0) return x;
        return function():* { return x(); };
    }
Collaborator

robertpenner commented Mar 30, 2012

This is fixed in AsUnit 4.0, where TestCase.addAsync() is delegated to
Async.add(), which gets a wrapper function of correct length from
here:

https://github.com/lukebayes/asunit/blob/master/asunit-4.0/src/asunit/framework/TimeoutCommand.as#L83

Robert

On Fri, Mar 30, 2012 at 1:12 AM, Strilanc
reply@reply.github.com
wrote:

The result of the addAsync method is a function whose length is not 0, even if the input argument is 0. If a tested method expects a callback to take 0 arguments, and checks this fact, the addAsync method prevents the test from succeeding and has to be worked around:

               private function testableAwaitCallback(func : Function) : Function {
                       var x:Function = this.addAsync(func);
                       if (func.length > 0) return x;
                       return function():* { return x(); };
               }


Reply to this email directly or view it on GitHub:
#12

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment