Created
June 8, 2011 18:57
-
-
Save dragthor/1015081 to your computer and use it in GitHub Desktop.
jquery.jsoncookie "size error" unit test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test( "size error", function() { | |
expect( 2 ); | |
var testValue = ""; | |
var testKey = "test"; | |
// Generates a 4095 byte cookie. | |
for (var i = 0; i < 4089 - testKey.length; i++) { testValue += "a"; } | |
raises( function() { $.cookie( testKey, testValue ) }, "size error thrown"); | |
equal( $.cookie( testKey ), null ); | |
}); | |
test( "large cookie", function() { | |
expect( 2 ); | |
var testValue = ""; | |
var testKey = "test"; | |
// Generates a 4094 byte cookie. | |
for (var i = 0; i < 4088 - testKey.length; i++) { testValue += "a"; } | |
$.cookie( testKey, testValue ); | |
equal( document.cookie, "test=%22" + testValue + "%22", "stored" ); | |
strictEqual( $.cookie( "test" ), testValue, "retrieved" ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment