Skip to content
This repository was archived by the owner on Sep 3, 2022. It is now read-only.

Commit 74023d6

Browse files
committed
Use a random key for all tests
1 parent 708cfec commit 74023d6

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

test/cookie.test.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,25 @@ var assert = require('proclaim');
44
var cookie = require('../lib').constructor.cookie;
55

66
describe('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

Comments
 (0)