JSTAPd::Manual::API - JSTAPd JavaScript API Reference
The Basic API gives you the tools to run the JavaScript tests. These functions are implemented on the window object. Unless otherwise stated, the functions should be compatible with that of Test::More
window
Declares the number of tests to be run. There is NO done_testing(), as it is very hard to detect how other (possibly asynchronous) code interact and affect the ending of a test.
These are all equivalent of the Test::More counterparts
Dumps the results up to this point to the console
The JSTAPd server keeps track of the Ajax requests (other than those that has to do with TAP results), and you can access them via this function. Once you called it, the server will empty the current list, so you won't be able to get the same request information again.
Returns a XmlHttpRequest object -- Useful if you are not using any sort of JavaScript frameworks to do the equivalent
Short-hand notation that does the equivalent of
return document.getElementById($domid);
return document.getElementsByTagName($tagname)[0];
JSTAPd は結構非同期してますが、これを直列的にテストを実行してくれるしくみです。
cho45 作の jsDeferred を参考にして作ってあります。
JSTAPd の client_script で指定されたスクリプトの、この jstapDeferred の next の中で実行されています。
基本的な next の使い方で、どんどん次の next にチェインして実行します。
jstapDeferred.next(function(){ return 'value'; }). next(function(val){ is(val, 'value'); });
next の戻り値に jstapDeferred のインスタンスを指定すると、次の next の直前に割り込む事ができます。
jstapDeferred.next(function(){ // 1 return jstapDeferred.next(function(){ // 2 }). next(function(){ // 3 }); }). next(function(val){ // 4 });
指定した msec 待ってから次の next を呼び出します。
jstapDeferred.wait(1000). next(function(val){ // 1秒後に実行 });
メッソッドチェーンの間でも使えます
jstapDeferred.next(function(){}). wait(1000). next(function(val){ // 1秒後に実行 });
callback が値を返すまで $retrycount の回数だけ callback を呼び続けます。 option.wait が指定されると指定された msec 待ってから retry します。
retry しても callback が値を返さなければ次以降のチェーンは実行されません。
jstapDeferred.retry(10, function(){ // なにか値を return するまで 10 回繰り返す }). next(function(val){ // callback の retry した値が val に入ってる });
jstapDeferred.next(function(){ return 'value'; }). retry(10, function(count, val){ is(val, 'value'); // なにか値を return するまで 10 回繰り返す }). next(function(val){ // callback の retry した値が val に入ってる });
$options の内容で XHR を実行して r.readyState == 4 になったら、 次のチェーンに進みます。
jstapDeferred.xhr({ method: 'GET', uri: '/foo/var', cache: false }). next(function(req){ is(req.readyState, 4); like(req.responseText, new RegExp('.')); });
jstapDeferred 組み込みの pop_tap_request
jstapDeferred.pop_request({ retry: 100, // 100 回リトライ wait: 100 // リトライは 100 msec おき }). next(function(req_list){ // pop_tap_request の callback に渡される引数が req_list に入る });
ok(), is(), like() などは非同期的に server に結果を送っているので、 server にこれらの結果を送り終わるまで wait してくれる為の物です。
jstapDeferred.next(function(){ ok(1); }). wait_dequeue(). next(function(){ // 上の ok(1) は、すでにサーバで処理された後 });
JSTAPd provides a set of tools that integrates with jQuery for easier testing. These are not enabled by default, so you must specify that you want it in your tests:
use JSTAPd::Suite; sub include_ex { return ( # whatever URL that holds your jquery file 'http://blahblah/jquery.min.js', # "magic" that enables jQuery <-> JSTAPd integration \'jquery-jstapd.js', ) } # XXX これってこんな感じにできないのかしら sub include_ex { return ( with_jquery($path_to_jquery) ) }
The test passes if the number of visible elements that match selector matches num
selector
num
If the selector returns multiple elements, then only the first one is used.
The test passes if none of the elements that match selector is visible.
The test passes if the text() value of the element specified by selector matches val.
text()
val
The test passes if the text() value of the element specified by selector does NOT match val.
The test passes if the text() value of the element specified by selector matches regexp. regexp must be a RegExp object.
regexp
RegExp
The test passes if the text() value of the element specified by selector does NOT match regexp. regexp must be a RegExp object.
The test passes if the form component's value of the element specified by selector matches val.
The test passes if the form component's value of the element specified by selector does NOT match val.
The test passes if the form component's value of the element specified by selector matches regex. regexp must be a RegExp object
regex
The test passes if the form component's value of the element specified by selector does NOT match regex. regexp must be a RegExp object
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'は結構非同期してますが、これを直列的にテストを実行してくれるしくみです。'. Assuming UTF-8
To install JSTAPd, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JSTAPd
CPAN shell
perl -MCPAN -e shell install JSTAPd
For more information on module installation, please visit the detailed CPAN module installation guide.