globalizejs/globalize

Code cleanup: Simplify assertRuntimeBind test utility

Open

#486 aperta il 23 ago 2015

Vedi su GitHub
 (0 commenti) (0 reazioni) (0 assegnatari)JavaScript (645 fork)batch import
help wantedquick change

Metriche repository

Star
 (4759 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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.

Guida contributor