asunit icon indicating copy to clipboard operation
asunit copied to clipboard

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

Open Strilanc opened this issue 13 years ago • 1 comments

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(); };
    }

Strilanc avatar Mar 29 '12 19:03 Strilanc

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 [email protected] 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: https://github.com/lukebayes/asunit/issues/12

robertpenner avatar Mar 30 '12 03:03 robertpenner