@@ -4,16 +4,25 @@ var assert = require('proclaim');
44var cookie = require ( '../lib' ) . constructor . cookie ;
55
66describe ( 'cookie' , function ( ) {
7+ // Use a random key for cookies
8+ // Workaround for flaky concurrent tests on Edge
9+ var testKey ;
10+
711 beforeEach ( function ( ) {
812 // Just to make sure that
913 // URIError is never thrown here.
1014 document . cookie = 'bad=%' ;
15+ testKey =
16+ '_' +
17+ Math . random ( )
18+ . toString ( 36 )
19+ . slice ( 2 ) ;
1120 } ) ;
1221
1322 afterEach ( function ( ) {
1423 // reset to defaults
1524 cookie . options ( { } ) ;
16- cookie . remove ( 'x' ) ;
25+ cookie . remove ( testKey ) ;
1726 } ) ;
1827
1928 describe ( '#get' , function ( ) {
@@ -22,39 +31,29 @@ describe('cookie', function() {
2231 } ) ;
2332
2433 it ( 'should get an existing cookie' , function ( ) {
25- cookie . set ( 'x' , { a : 'b' } ) ;
26- assert . deepEqual ( cookie . get ( 'x' ) , { a : 'b' } ) ;
34+ cookie . set ( testKey , { a : 'b' } ) ;
35+ assert . deepEqual ( cookie . get ( testKey ) , { a : 'b' } ) ;
2736 } ) ;
2837
2938 it ( 'should not throw an error on a malformed cookie' , function ( ) {
30- document . cookie = 'x =y';
31- assert ( cookie . get ( 'x' ) === null ) ;
39+ document . cookie = testKey + ' =y';
40+ assert ( cookie . get ( testKey ) === null ) ;
3241 } ) ;
3342 } ) ;
3443
3544 describe ( '#set' , function ( ) {
3645 it ( 'should set a cookie' , function ( ) {
37- // Use a random key for the cookie
38- // Workaround for flaky concurrent tests on Edge
39- var key = Math . random ( )
40- . toString ( 36 )
41- . slice ( 2 ) ;
42-
43- try {
44- cookie . set ( key , { a : 'b' } ) ;
45- assert . deepEqual ( cookie . get ( key ) , { a : 'b' } ) ;
46- } finally {
47- cookie . remove ( key ) ;
48- }
46+ cookie . set ( testKey , { a : 'b' } ) ;
47+ assert . deepEqual ( cookie . get ( testKey ) , { a : 'b' } ) ;
4948 } ) ;
5049 } ) ;
5150
5251 describe ( '#remove' , function ( ) {
5352 it ( 'should remove a cookie' , function ( ) {
54- cookie . set ( 'x' , { a : 'b' } ) ;
55- assert . deepEqual ( cookie . get ( 'x' ) , { a : 'b' } ) ;
56- cookie . remove ( 'x' ) ;
57- assert ( cookie . get ( 'x' ) === null ) ;
53+ cookie . set ( testKey , { a : 'b' } ) ;
54+ assert . deepEqual ( cookie . get ( testKey ) , { a : 'b' } ) ;
55+ cookie . remove ( testKey ) ;
56+ assert ( cookie . get ( testKey ) === null ) ;
5857 } ) ;
5958 } ) ;
6059
0 commit comments