-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathcookie.js
47 lines (40 loc) · 1.08 KB
/
cookie.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import cookie from '../src/cookie.js';
describe('Cookie', () => {
before(() => {
cookie.reset();
});
afterEach(() => {
cookie.remove('x');
cookie.reset();
});
describe('get', () => {
it('should get an existing cookie', () => {
cookie.set('x', { a: 'b' });
assert.deepEqual(cookie.get('x'), { a: 'b' });
});
it('should not throw an error on a malformed cookie', () => {
document.cookie = 'x=y; path=/';
assert.isNull(cookie.get('x'));
});
});
describe('remove', () => {
it('should remove a cookie', () => {
cookie.set('x', { a: 'b' });
assert.deepEqual(cookie.get('x'), { a: 'b' });
cookie.remove('x');
assert.isNull(cookie.get('x'));
});
});
describe('options', () => {
it('should set default options', () => {
assert.deepEqual(cookie.options(), {
expirationDays: undefined,
domain: undefined,
});
});
it('should save options', () => {
cookie.options({ expirationDays: 1 });
assert.equal(cookie.options().expirationDays, 1);
});
});
});