Skip to content

Code cleanup: Simplify assertRuntimeBind test utility #486

@rxaviers

Description

@rxaviers

In #436, @jzaefferer said the below. The goal of this issue is following-up with this change.

Actually, this allows a custom tests to be performed by each calling code. For example: https://github.com/jquery/globalize/pull/436/files#diff-9ee4a6f38e08bc680f4668d25dedaff8R30, https://github.com/jquery/globalize/pull/436/files#diff-3b257e2c8b293a57b0336b413514f034R110. Please, just let me know if I misinterpreted your comment.

Its called synchronously with an argument passed by the caller. Thats trivial to do without the callback. From test/functional/number/number-formatter.js:

util.assertRuntimeBind(
    assert,
    Globalize.numberFormatter(),
    "b468386326",
    "Globalize(\"en\").numberFormatter({})",
    function( runtimeArgs ) {
        assert.equal( JSON.stringify( runtimeArgs[ 0 ] ), "[\"\",null,1,0,3,null,null," +
            "null,3,null,\"\",\"#,##0.###\",\"-#,##0.###\",\"-\",\"\",null,\"∞\",\"NaN\",{" +
            "\".\":\".\",\",\":\",\",\"%\":\"%\",\"+\":\"+\",\"-\":\"-\",\"E\":\"E\",\"‰\":" +
            "\"‰\"},null]"
        );
        assert.ok( "generatorString" in runtimeArgs[ 0 ][ 15 ] );
        assert.equal( runtimeArgs[ 0 ][ 15 ].generatorString(), "numberRound()" );
    }
);

turns to

var formatter = Globalize.numberFormatter() 
util.assertRuntimeBind( assert, formatter, "b468386326", "Globalize(\"en\").numberFormatter({})" );
assert.equal( JSON.stringify( formatter.runtimeArgs[ 0 ] ), "[\"\",null,1,0,3,null,null," +
    "null,3,null,\"\",\"#,##0.###\",\"-#,##0.###\",\"-\",\"\",null,\"∞\",\"NaN\",{" +
    "\".\":\".\",\",\":\",\",\"%\":\"%\",\"+\":\"+\",\"-\":\"-\",\"E\":\"E\",\"‰\":" +
    "\"‰\"},null]"
);
assert.ok( "generatorString" in formatter.runtimeArgs[ 0 ][ 15 ] );
assert.equal( formatter.runtimeArgs[ 0 ][ 15 ].generatorString(), "numberRound()" );

And you can drop the noop function arguments and you get simpler stacktraces.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions