Skip to content

Instantly share code, notes, and snippets.

@dragthor
Created June 8, 2011 18:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dragthor/1015081 to your computer and use it in GitHub Desktop.
Save dragthor/1015081 to your computer and use it in GitHub Desktop.
jquery.jsoncookie "size error" unit test
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