2
0
mirror of https://github.com/tenrok/axios.git synced 2026-06-17 19:21:29 +03:00
Files
axios/test/specs/helpers/cookies.spec.js
T
Jay ef3711d1b3 feat: implement prettier and fix all issues (#7385)
* feat: implement prettier and fix all issues

* fix: failing tests

* fix: implement feedback from codel, ai etc

* chore: dont throw in trim function

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* fix: incorrect fix

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-02-14 16:59:48 +02:00

40 lines
1.1 KiB
JavaScript

import cookies from '../../../lib/helpers/cookies';
describe('helpers::cookies', function () {
afterEach(function () {
// Remove all the cookies
const expires = Date.now() - 60 * 60 * 24 * 7;
document.cookie
.split(';')
.map(function (cookie) {
return cookie.split('=')[0];
})
.forEach(function (name) {
document.cookie = name + '=; expires=' + new Date(expires).toGMTString();
});
});
it('should write cookies', function () {
cookies.write('foo', 'baz');
expect(document.cookie).toEqual('foo=baz');
});
it('should read cookies', function () {
cookies.write('foo', 'abc');
cookies.write('bar', 'def');
expect(cookies.read('foo')).toEqual('abc');
expect(cookies.read('bar')).toEqual('def');
});
it('should remove cookies', function () {
cookies.write('foo', 'bar');
cookies.remove('foo');
expect(cookies.read('foo')).toEqual(null);
});
it('should uri encode values', function () {
cookies.write('foo', 'bar baz%');
expect(document.cookie).toEqual('foo=bar%20baz%25');
});
});