{"id":904,"date":"2012-08-31T13:42:15","date_gmt":"2012-08-31T19:42:15","guid":{"rendered":"http:\/\/www.mooreds.com\/wordpress\/?p=904"},"modified":"2012-08-31T13:53:24","modified_gmt":"2012-08-31T19:53:24","slug":"running-async-tests-with-qunit-and-sinon","status":"publish","type":"post","link":"https:\/\/www.mooreds.com\/wordpress\/archives\/904","title":{"rendered":"Running async tests with qunit and sinon"},"content":{"rendered":"<p>I ran into an issue running <a href=\"http:\/\/qunitjs.com\/cookbook\/#asynchronous_callbacks\">async tests<\/a> with <a href=\"http:\/\/qunitjs.com\/\">qunit<\/a> and <a href=\"http:\/\/sinonjs.org\/\">sinon<\/a>.\u00a0 For a primer on doing this, see <a href=\"http:\/\/addyosmani.com\/blog\/unit-testing-backbone-js-apps-with-qunit-and-sinonjs\/\">this great article<\/a>.<\/p>\n<p>Basically, the asyncTest never returned.\u00a0 This manifested itself in the html view of the tests like this (left is success, right is where the test never returns&#8211;note the white):<\/p>\n<div id=\"gallery_904_1\" class=\"row\">\r\n\t    \t<div id=\"904-image-908\" class=\"col-xs-12 col-sm-4 col-md-4\">\r\n        \t\t\t\t\t\r\n\t\t\t<div class=\"thumbnail\">\r\n        \t\t\t\t\t\r\n\t\t\t\t                <a href=\"#\" data-toggle=\"modal\" data-target=\"#904-modal-908\">\r\n                \t<img loading=\"lazy\" decoding=\"async\" width=\"530\" height=\"238\" src=\"http:\/\/edit.mooreds.com\/wordpress\/wp-content\/uploads\/2012\/08\/qunit-succeed.png\" class=\"attachment-large size-large\" alt=\"\" srcset=\"http:\/\/edit.mooreds.com\/wordpress\/wp-content\/uploads\/2012\/08\/qunit-succeed.png 530w, http:\/\/edit.mooreds.com\/wordpress\/wp-content\/uploads\/2012\/08\/qunit-succeed-300x134.png 300w\" sizes=\"auto, (max-width: 530px) 100vw, 530px\" \/>                <\/a>\r\n                            <\/div>\r\n        <\/div>\r\n        \t<div id=\"904-image-909\" class=\"col-xs-12 col-sm-4 col-md-4\">\r\n        \t\t\t\t\t\r\n\t\t\t<div class=\"thumbnail\">\r\n        \t\t\t\t\t\r\n\t\t\t\t                <a href=\"#\" data-toggle=\"modal\" data-target=\"#904-modal-909\">\r\n                \t<img loading=\"lazy\" decoding=\"async\" width=\"644\" height=\"267\" src=\"http:\/\/edit.mooreds.com\/wordpress\/wp-content\/uploads\/2012\/08\/qunit-fail.png\" class=\"attachment-large size-large\" alt=\"\" srcset=\"http:\/\/edit.mooreds.com\/wordpress\/wp-content\/uploads\/2012\/08\/qunit-fail.png 644w, http:\/\/edit.mooreds.com\/wordpress\/wp-content\/uploads\/2012\/08\/qunit-fail-300x124.png 300w\" sizes=\"auto, (max-width: 644px) 100vw, 644px\" \/>                <\/a>\r\n                            <\/div>\r\n        <\/div>\r\n    <div class=\"clearfix visible-sm-block\"><\/div>\r\n<\/div>\n<p>Turns out that sinon-qunit adapter has <a href=\"https:\/\/github.com\/cjohansen\/sinon-qunit\/issues\/3\">sinon fake the browser timer<\/a>, so setTimeout doesn&#8217;t work as expected.<\/p>\n<p>To fix, just turn off the timer faking for a single test:\u00a0<code>this.clock.restore()<\/code> or <code>sinon.config.useFakeTimers = false<\/code> to disable this for all tests.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I ran into an issue running async tests with qunit and sinon.\u00a0 For a primer on doing this, see this great article. Basically, the asyncTest never returned.\u00a0 This manifested itself [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[54,58],"tags":[],"class_list":["post-904","post","type-post","status-publish","format-standard","hentry","category-javascript","category-testing"],"_links":{"self":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/904","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/comments?post=904"}],"version-history":[{"count":6,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/904\/revisions"}],"predecessor-version":[{"id":912,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/posts\/904\/revisions\/912"}],"wp:attachment":[{"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/media?parent=904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/categories?post=904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mooreds.com\/wordpress\/wp-json\/wp\/v2\/tags?post=904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}