define('DISALLOW_FILE_EDIT', true);{"id":4217,"date":"2012-06-12T18:12:54","date_gmt":"2012-06-12T23:12:54","guid":{"rendered":"http:\/\/www.unfocus.com\/?p=4217"},"modified":"2012-08-24T14:11:30","modified_gmt":"2012-08-24T19:11:30","slug":"signalslite-js-unit-testing-and-buggy-ie","status":"publish","type":"post","link":"http:\/\/www.unfocus.com\/2012\/06\/12\/signalslite-js-unit-testing-and-buggy-ie\/","title":{"rendered":"SignalsLite.js, Unit Testing, and Buggy IE"},"content":{"rendered":"

I decided to finally learn unit testing, so I downloaded QUnit (after looking at the 20,000 different unit testing options), and figured I’d give porting tiny SignalsLite to JavaScript a try, and see how the process goes.<\/p>\n

While doing that, I found a crazy IE7\/IE8 JS bug, that I’m sure has had me scratching my head in the past. Here is a quick unit test to show the problem:<\/p>\n

[sourcecode language=”javascript”]
\ntest( "Basic Requirements", function testReqs() {
\n\texpect(1);
\n\tvar T;
\n\t(function makeT() {
\n\t\tT=function T(){}
\n\t\tT.prototype.test = 1;
\n\t})();
\n\tok((new T).test, "Instance of exported T should have prototype methods");
\n});
\n[\/sourcecode]<\/p>\n

If you run that IE7 or IE8 it’ll fail!<\/p>\n

The cool thing is, without having created unit tests for SignalsLite.js, I would never have known that could be an issue, and instead would continue to scratch my head when stuff like that broke in IE7\/8. I found this because I was trying to export SignalLite from within a closure (I try to always define my stuff inside of closures to avoid namespace pollution), with this:<\/p>\n

[sourcecode language=”javascript”]
\n(function() { "use strict"; \/\/ standard header<\/p>\n

\/\/ naming inline functions makes the debug console easier to read.
\nwindow.SignalLite = function SignalLite() {
\n\t\/\/ stuff
\n}
\nSignalLite.prototype = {
\n\t\/\/ methods
\n};<\/p>\n

\/\/ The fix is to use an anonymous function, or export elsewhere:
\n\/\/ window.SignalLite = SignalLite;<\/p>\n

})();
\n[\/sourcecode]<\/p>\n

For whatever reason, that doesn’t work in IE7 and IE8. Unit testing is crazy!<\/p>\n

If you are interested, go fork SignalsLite.json GitHib<\/a>.<\/p>\n

P.S. You can run the SignalsLite.js unit tests here<\/a> to see the fail for yourself<\/del>! I disabled that test in the SignalsLite.js tests.<\/p>\n","protected":false},"excerpt":{"rendered":"

I decided to finally learn unit testing, so I downloaded QUnit (after looking at the 20,000 different unit testing options), and figured I’d give porting tiny SignalsLite to JavaScript a try, and see how the process goes. While doing that, I found a crazy IE7\/IE8 JS bug, that I’m sure has had me scratching my … Continue reading “SignalsLite.js, Unit Testing, and Buggy IE”<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[173,37],"tags":[],"_links":{"self":[{"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/posts\/4217"}],"collection":[{"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/comments?post=4217"}],"version-history":[{"count":5,"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/posts\/4217\/revisions"}],"predecessor-version":[{"id":4220,"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/posts\/4217\/revisions\/4220"}],"wp:attachment":[{"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/media?parent=4217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/categories?post=4217"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.unfocus.com\/wp-json\/wp\/v2\/tags?post=4217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}