Skip to content
Browse files

Merge pull request #144 from peterbraden/master

Unit test for a9f95e5
  • Loading branch information...
2 parents 35cab89 + 9b9611f commit ecb31b374a2fbc2bd7f170c0b09abe5452af4465 @asual committed Aug 22, 2012
Showing with 69 additions and 2 deletions.
  1. +69 −2 test/test.js
View
71 test/test.js
@@ -316,15 +316,15 @@ asyncTest("Hash Change Event test", function() {
equals(hashChangeCount, 1)
e.preventDefault();
+ start()
}
$.address.value('/')
.change(hashChangeFunc)
.hash('foobar')
- .unbind('hashchange')
+ .unbind('change')
- start()
}, 100)
})
@@ -337,6 +337,73 @@ asyncTest("Prevent Default Test", function(){
}, 20)
})
+asyncTest("Subsequent prevent default should work", function(){
+
+ var hashChangeCount = 0
+
+ setTimeout(function() {
+ var hashChangeFunc = function(e){
+ hashChangeCount ++;
+ e.preventDefault();
+ }
+
+ $.address
+ .change(hashChangeFunc)
+ .value('?foobar')
+
+ }, 50)
+
+ setTimeout(function(){
+ equals($.address.value(), '')
+ equal( hashChangeCount, 1, "Change Happened")
+ $.address.value('bar')
+ }, 100)
+
+ setTimeout(function(){
+ equals($.address.value(), '')
+ equal(hashChangeCount, 2);
+ $.address.unbind('change')
+ .value('?foo')
+ }, 150)
+
+ // Test unbind
+ setTimeout(function(){
+ equal($.address.value(), '?foo')
+ equal(hashChangeCount, 2);
+ $.address.value('/')
+ start()
+ }, 200)
+
+
+})
+
+
+
+asyncTest('ensure code in hash is not executed (see commit a9f95e5885a9e)', function(){
+ setTimeout(function(){
+ var called = 0
+
+ //place a function in the global namespace, this one should get called by the injected code
+ window.omg = function(){
+ called++;
+ };
+
+ $.address.change(function(){
+ equal(called, 0);
+
+ $.address.value('/');
+ delete window.omg;
+
+ start();
+ });
+
+ //change the hash
+ window.location.hash = "'-window.top.omg(1)-'";
+ }, 100)
+
+
+})
+
setTimeout(function() {
$.address.value('/');

0 comments on commit ecb31b3

Please sign in to comment.
Something went wrong with that request. Please try again.