diff options
author | Bryan Berry <bryan@olenepal.org> | 2009-11-20 17:39:51 (GMT) |
---|---|---|
committer | Bryan Berry <bryan@olenepal.org> | 2009-11-20 17:39:51 (GMT) |
commit | 12dd211d05b69b0b852d0e0985e8f9e923263042 (patch) | |
tree | fb2a741909da23baccb16bd86341da9b0b458dd5 /tests | |
parent | 516ce032de1b8a29b1d13e471695bfaf102912de (diff) |
fixed enabling and disabling buttons in adding_up_canvas. Fixed test for Karma.karma.ready() for whatever reason it only works if run last. I think it is an issue w/ qunit. Moved Karma.karma.reset to tests.js
Diffstat (limited to 'tests')
-rwxr-xr-x | tests/js/tests.js | 79 | ||||
-rw-r--r-- | tests/js/tests1.js | 67 |
2 files changed, 125 insertions, 21 deletions
diff --git a/tests/js/tests.js b/tests/js/tests.js index 789b988..d66af1a 100755 --- a/tests/js/tests.js +++ b/tests/js/tests.js @@ -34,6 +34,34 @@ return regex.test(errorMsg); }; + //unit test suite uses this function + Karma.karma.reset = function () { + if (this.statusDiv){ + this.statusDiv.parentNode.removeChild(this.statusDiv); + } + + var starterMsg = document.getElementById('starterMsg'); + if(starterMsg){ + starterMsg.parentNode.removeChild(starterMsg); + } + + this._assetPath = "assets/", + this.locale = undefined, + this._localized = false, + this._localePath = "", + this.images = {}, + this.canvases = {}, + this.sounds = {}, + this.svgs = {}, + this.videos = {}, + this.initialized = false, + this.statusDiv= undefined, + this._counters = { total : 0, errors : 0, loaded : 0}; + this.loaderDiv = undefined; + return this; + }; + + module("Module Helpers"); @@ -182,7 +210,8 @@ k.reset(); }); - + + test("Karma.karma.ready()", function () { expect(3); ok(shouldError(function () {k.ready();}), "Uninitialized karma instance " + @@ -207,25 +236,7 @@ k.reset(); }); - asyncTest("Karma.karma.ready() check callback execution", 2, - function(){ - //test that callback isn't called while asset isn't ready yet - var ninjaName = "Bruce Lee"; - var testCb = function () { ninjaName = "Chuck Norris";}; - k.reset().init(); - k._counters.total = 5000; - k.ready(testCb); - ok( ninjaName === "Bruce Lee", "callback not called before all assets loaded"); - k._counters.total = 0; - - //wait for callback to be called by ready - setTimeout(function() { - ok (ninjaName === "Chuck Norris", - "ready() calls callback after assets loaded"); - k.reset(); - start();}, - 200); - }); + test("karma.isValidLocale(locale)", function () { @@ -891,5 +902,31 @@ */ - + //for whatever reason, this test only works if run last + asyncTest("Karma.karma.ready() check callback execution", + function(){ + expect(2); + //test that callback isn't called while asset isn't ready yet + var foo = "bar"; + var testCb = function () { + foo = "baz"; + }; + + k.reset().init(); + k._counters.total = 5000; + k.ready(testCb); + ok( foo === "bar", "callback not called before all assets loaded"); + k._counters.total = k._counters.loaded = 0; + + //wait for callback to be called by ready + setTimeout(function() { + ok (foo === "baz", + "ready() calls callback after assets loaded"); + delete foo; + start(); + }, + 10); + }); + + });
\ No newline at end of file diff --git a/tests/js/tests1.js b/tests/js/tests1.js new file mode 100644 index 0000000..e79b743 --- /dev/null +++ b/tests/js/tests1.js @@ -0,0 +1,67 @@ + $(document).ready( + function(){ + // k is a shortcut for the Karma object + var k = Karma.karma; + + var hasProperties = function (properties) { + for ( prop in properties) { + if (!this[prop]){ + return false; + } + else { + return true; + } + } + }; + + var shouldError = function ( cb ){ + try { + cb(); + } + catch (e) { + return true; + } + return false; + }; + + var shouldNotError = function ( cb ) { + return !shouldError( cb ); + }; + + var checkErrorMsg = function(){ + var errorMsg = $('#errorList>li').text(); + var regex = new RegExp('error', 'i'); + return regex.test(errorMsg); + }; + + module("Module Helpers"); + + + asyncTest("Karma.karma.ready() check callback execution", + function(){ + expect(2); + //test that callback isn't called while asset isn't ready yet + k.foo = "bar"; + var testCb = function () { + k.foo = "baz"; + console.log(k.foo); + }; + + k.reset().init(); + k._counters.total = 5000; + k.ready(testCb); + ok( k.foo === "bar", "callback not called before all assets loaded"); + k._counters.total = k._counters.loaded = 0; + + //wait for callback to be called by ready + setTimeout(function() { + console.log(k.foo); + ok (k.foo === "baz", + "ready() calls callback after assets loaded"); + delete k.foo; + start(); + }, + 100); + }); + + });
\ No newline at end of file |