globalizejs / globalizejs/globalize

Code cleanup: Simplify assertRuntimeBind test utility

Open
#486 0 comments 0 reactions 0 assignees View on GitHub
help wanted quick change
Dominant language
JavaScript
Stars
4.8k
Forks
585
PR merge metrics
No merged PRs in 30d

Description

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:

``` 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

``` js
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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.