
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
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);
Short-hand notation that does the equivalent of
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
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.
If the selector returns multiple elements, then only the first one is used.
The test passes if the text() value of the element specified by selector matches val.
If the selector returns multiple elements, then only the first one is used.
The test passes if the text() value of the element specified by selector does NOT match val.
If the selector returns multiple elements, then only the first one is used.
The test passes if the text() value of the element specified by selector matches regexp. regexp must be a RegExp object.
If the selector returns multiple elements, then only the first one is used.
The test passes if the text() value of the element specified by selector does NOT match regexp. regexp must be a RegExp object.
If the selector returns multiple elements, then only the first one is used.
The test passes if the form component's value of the element specified by selector matches val.
If the selector returns multiple elements, then only the first one is used.
The test passes if the form component's value of the element specified by selector does NOT match val.
If the selector returns multiple elements, then only the first one is used.
The test passes if the form component's value of the element specified by selector matches regex. regexp must be a RegExp object
If the selector returns multiple elements, then only the first one is used.
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
If the selector returns multiple elements, then only the first one is used.