{"id":3173,"date":"2014-01-17T01:36:48","date_gmt":"2014-01-17T07:36:48","guid":{"rendered":"http:\/\/bililite.com\/blog\/?p=3173"},"modified":"2014-01-17T01:37:35","modified_gmt":"2014-01-17T07:37:35","slug":"unit-testing","status":"publish","type":"post","link":"https:\/\/bililite.com\/blog\/2014\/01\/17\/unit-testing\/","title":{"rendered":"Unit testing"},"content":{"rendered":"<p>I've finally decided to join the 21st century and use automated testing on my <code>bililiteRange<\/code> code; I'm using <a href=\"http:\/\/qunitjs.com\/\">QUnit<\/a>, with tests on <a href=\"https:\/\/github.com\/dwachss\/bililiteRange\/tree\/master\/test\">github<\/a>. I want to bililiteRange test on all three types of editable elements, <code class=\"language-html\" >&lt;input type=text&gt;<\/code>, <code class=\"language-html\" >&lt;textarea&gt;<\/code>, and <code class=\"language-html\" >&lt;div contenteditable&gt;<\/code>, so I created a convenience function to run each test on each type of element, with<\/p>\r\n<pre><code class=\"language-javascript\" >var elements = ['div', 'textarea', 'input'];\r\nfunction multitest (message, fn){\r\n  elements.forEach( function(name){\r\n    test(message, function(){\r\n      var $el = $('<'+name'>').attr('contenteditable','').appendTo('#qunit-fixture');\r\n      fn($el); \/\/ the testing function\r\n    });\r\n  });\r\n}<\/code><\/pre>\r\n<p>And the testing code calls <code class=\"language-javascript\" >multitest<\/code> rather than <code class=\"language-javascript\" >test<\/code>.<\/p>\r\n\r\n<p>I feel so modern; maybe I'll start complaining about waterfalls next.<\/p>","protected":false},"excerpt":{"rendered":"I've finally decided to join the 21st century and use automated testing on my bililiteRange code; I'm using QUnit, with tests on github. I want to bililiteRange test on all three types of editable elements, &lt;input type=text&gt;, &lt;textarea&gt;, and &lt;div contenteditable&gt;, so I created a convenience function to run each test on each type of [&hellip;]","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,5],"tags":[],"_links":{"self":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3173"}],"collection":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/comments?post=3173"}],"version-history":[{"count":2,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3173\/revisions"}],"predecessor-version":[{"id":3175,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/posts\/3173\/revisions\/3175"}],"wp:attachment":[{"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/media?parent=3173"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/categories?post=3173"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bililite.com\/blog\/wp-json\/wp\/v2\/tags?post=3173"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}