|
1 | 1 | // https://github.com/axemclion/grunt-saucelabs#test-result-details-with-qunit |
2 | | -(function() { |
| 2 | +(function () { |
3 | 3 | "use strict"; |
4 | 4 |
|
5 | 5 | var log = []; |
@@ -216,10 +216,17 @@ test('defaults', function () { |
216 | 216 | ok(Cookies.set('c', 'v', { path: '/bar' }).match(/path=\/bar/), 'options argument has precedence'); |
217 | 217 | }); |
218 | 218 |
|
219 | | -test('Quote as the first character in the cookie value', function () { |
220 | | - expect(1); |
221 | | - Cookies.set('c', '"'); |
222 | | - strictEqual(Cookies.get('c'), '"', 'should handle the quote character'); |
| 219 | +test('Quote in the cookie value', function () { |
| 220 | + expect(3); |
| 221 | + |
| 222 | + Cookies.set('quote', '"'); |
| 223 | + strictEqual(Cookies.get('quote'), '"', 'should print the quote character'); |
| 224 | + |
| 225 | + Cookies.set('without-last', '"content'); |
| 226 | + strictEqual(Cookies.get('without-last'), '"content', 'should print the quote character'); |
| 227 | + |
| 228 | + Cookies.set('without-first', 'content"'); |
| 229 | + strictEqual(Cookies.get('without-first'), 'content"', 'should print the quote character'); |
223 | 230 | }); |
224 | 231 |
|
225 | 232 | test('RFC 6265 disallowed characters in cookie-octet', function () { |
@@ -342,10 +349,79 @@ test('[] used in name', function () { |
342 | 349 | strictEqual(document.cookie, '', 'delete the cookie'); |
343 | 350 | }); |
344 | 351 |
|
345 | | -module('conversion', lifecycle); |
| 352 | +module('converters', lifecycle); |
346 | 353 |
|
347 | | -test('read converter', function() { |
| 354 | +test('read converter', function () { |
348 | 355 | expect(1); |
349 | 356 | Cookies.set('c', '1'); |
350 | 357 | strictEqual(Cookies.get('c', Number), 1, 'converts read value'); |
351 | 358 | }); |
| 359 | + |
| 360 | +module('JSON handling', lifecycle); |
| 361 | + |
| 362 | +test('Number', function () { |
| 363 | + expect(2); |
| 364 | + Cookies.set('c', 1); |
| 365 | + strictEqual(Cookies.getJSON('c'), 1, 'should handle a Number'); |
| 366 | + strictEqual(Cookies.get('c'), '1', 'should return a String'); |
| 367 | +}); |
| 368 | + |
| 369 | +test('Boolean', function () { |
| 370 | + expect(2); |
| 371 | + Cookies.set('c', true); |
| 372 | + strictEqual(Cookies.getJSON('c'), true, 'should handle a Boolean'); |
| 373 | + strictEqual(Cookies.get('c'), 'true', 'should return a Boolean'); |
| 374 | +}); |
| 375 | + |
| 376 | +test('Array Literal', function () { |
| 377 | + expect(2); |
| 378 | + Cookies.set('c', ['v']); |
| 379 | + deepEqual(Cookies.getJSON('c'), ['v'], 'should handle Array Literal'); |
| 380 | + strictEqual(Cookies.get('c'), '["v"]', 'should return a String'); |
| 381 | +}); |
| 382 | + |
| 383 | +test('Array Constructor', function () { |
| 384 | + /*jshint -W009 */ |
| 385 | + expect(2); |
| 386 | + var value = new Array(); |
| 387 | + value[0] = 'v'; |
| 388 | + Cookies.set('c', value); |
| 389 | + deepEqual(Cookies.getJSON('c'), ['v'], 'should handle Array Constructor'); |
| 390 | + strictEqual(Cookies.get('c'), '["v"]', 'should return a String'); |
| 391 | +}); |
| 392 | + |
| 393 | +test('Object Literal', function () { |
| 394 | + expect(2); |
| 395 | + Cookies.set('c', {k: 'v'}); |
| 396 | + deepEqual(Cookies.getJSON('c'), {k: 'v'}, 'should handle Object Literal'); |
| 397 | + strictEqual(Cookies.get('c'), '{"k":"v"}', 'should return a String'); |
| 398 | +}); |
| 399 | + |
| 400 | +test('Object Constructor', function () { |
| 401 | + /*jshint -W010 */ |
| 402 | + expect(2); |
| 403 | + var value = new Object(); |
| 404 | + value.k = 'v'; |
| 405 | + Cookies.set('c', value); |
| 406 | + deepEqual(Cookies.getJSON('c'), {k: 'v'}, 'should handle Object Constructor'); |
| 407 | + strictEqual(Cookies.get('c'), '{"k":"v"}', 'should return a String'); |
| 408 | +}); |
| 409 | + |
| 410 | +test('Use String(value) for unsupported objects that do not stringify into JSON', function() { |
| 411 | + expect(4); |
| 412 | + |
| 413 | + Cookies.set('date', new Date(2015, 04, 13, 0, 0, 0, 0)); |
| 414 | + strictEqual(Cookies.get('date').indexOf('"'), -1, 'should not quote the stringified Date object'); |
| 415 | + strictEqual(Cookies.getJSON('date').indexOf('"'), -1, 'should not quote the stringified Date object'); |
| 416 | + |
| 417 | + Cookies.set('function', function (){}); |
| 418 | + strictEqual(Cookies.get('function'), undefined, 'should return undefined for function object'); |
| 419 | + strictEqual(Cookies.getJSON('function'), undefined, 'should return undefined for function object'); |
| 420 | +}); |
| 421 | + |
| 422 | +test('Call to read all cookies with mixed json', function () { |
| 423 | + Cookies.set('c', { foo: 'bar' }); |
| 424 | + Cookies.set('c2', 'v'); |
| 425 | + deepEqual(Cookies.getJSON(), { c: { foo: 'bar' }, c2: 'v' }, 'returns JSON parsed cookies'); |
| 426 | + deepEqual(Cookies.get(), { c: '{"foo":"bar"}', c2: 'v' }, 'returns unparsed cookies'); |
| 427 | +}); |
0 commit comments