{"id":1095,"date":"2018-10-24T20:44:03","date_gmt":"2018-10-24T20:44:03","guid":{"rendered":"https:\/\/lab.florianschwarz.net\/PennController\/?post_type=yada_wiki&#038;p=1095"},"modified":"2018-10-24T20:44:37","modified_gmt":"2018-10-24T20:44:37","slug":"function-test-is","status":"publish","type":"yada_wiki","link":"https:\/\/lab.florianschwarz.net\/PennController\/wiki\/function-test-is\/","title":{"rendered":"function.test.is"},"content":{"rendered":"<p class='command-format'><code>getFunction(id).test.is()<\/code><\/p>\n<p class='command-format'>or <code>getFunction(id).test.is( value )<\/code><\/p>\n<p>Executes the function and tests the value it returns. If you specify no value, it yields success if the return value is 0, <em>null<\/em>, <em>undefined<\/em> or <em>false<\/em>.<\/p>\n<p><strong>NOTE:<\/strong> remember that the expression you pass as the test value is executed at the very beginning of the experiment. So calling <em>getFunction(&#8220;myFunction&#8221;).test.is( <strong>Date.now()<\/strong> )<\/em> will test that the function returns the timestamp <em>corresponding to the beginning of the experiment<\/em>. In this case, you may consider rewriting your function so it takes care of testing <em>Date.now()<\/em> and returns <em>true<\/em> or <em>false<\/em> in consequence.<\/p>\n<p><strong>Example:<\/strong><\/p>\n<p>[js highlight=&#8221;10,11&#8243; try=&#8221;true&#8221;]newFunction(&#8220;timestampMultipleOfThree&#8221;, () =&gt; Date.now() % 3 )<br \/>\n,<br \/>\nnewText(&#8220;missed&#8221;, &#8220;Bad luck, try again!&#8221;)<br \/>\n    .settings.color(&#8220;red&#8221;)<br \/>\n    .settings.bold()<br \/>\n,<br \/>\nnewButton(&#8220;myButton&#8221;, &#8220;Click me&#8221;)<br \/>\n    .print()<br \/>\n    .wait(<br \/>\n        getFunction(&#8220;timestampMultipleOfThree&#8221;)<br \/>\n            .testNot.is()<br \/>\n            .success( getText(&#8220;missed&#8221;).remove() )<br \/>\n            .failure( getText(&#8220;missed&#8221;).print() )<br \/>\n    )[\/js]<\/p>\n<p>Adds a button to the screen whose clicks are validated only if happening at a time when the timestamp is <strong>not<\/strong> a multiple of 3 (i.e., the modulo value returned by the function is <strong>different<\/strong> from 0).<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"inline_featured_image":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"wiki_cats":[13,5,4,19,15],"wiki_tags":[],"class_list":["post-1095","yada_wiki","type-yada_wiki","status-publish","hentry","wiki_cats-command","wiki_cats-documentation","wiki_cats-element","wiki_cats-function-element","wiki_cats-test-command"],"_links":{"self":[{"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/yada_wiki\/1095","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/yada_wiki"}],"about":[{"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/types\/yada_wiki"}],"author":[{"embeddable":true,"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/comments?post=1095"}],"version-history":[{"count":2,"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/yada_wiki\/1095\/revisions"}],"predecessor-version":[{"id":1099,"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/yada_wiki\/1095\/revisions\/1099"}],"wp:attachment":[{"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/media?parent=1095"}],"wp:term":[{"taxonomy":"wiki_cats","embeddable":true,"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/wiki_cats?post=1095"},{"taxonomy":"wiki_tags","embeddable":true,"href":"https:\/\/lab.florianschwarz.net\/PennController\/wp-json\/wp\/v2\/wiki_tags?post=1095"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}