NeahNew/node_modules/cookies-next/lib/client/client.test.js
2025-05-03 14:17:46 +02:00

45 lines
2.0 KiB
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var index_1 = require("../index");
describe('Client-side cookie operations', function () {
test('getCookies should return all cookies', function () {
(0, index_1.setCookie)('key1', 'value1');
(0, index_1.setCookie)('key2', 'value2');
var cookies = (0, index_1.getCookies)();
expect(cookies).toEqual({ key1: 'value1', key2: 'value2' });
});
test('setCookie should set a cookie', function () {
(0, index_1.setCookie)('testKey', 'testValue');
expect(document.cookie).toContain('testKey=testValue');
});
test('getCookie should retrieve a set cookie', function () {
document.cookie = 'testKey2=testValue2';
var value = (0, index_1.getCookie)('testKey2');
expect(value).toBe('testValue2');
});
test('deleteCookie should remove a cookie', function () {
document.cookie = 'testKey3=testValue3';
(0, index_1.deleteCookie)('testKey3');
expect(document.cookie).not.toContain('testKey3=testValue3');
});
test('hasCookie should return true for existing cookie', function () {
document.cookie = 'testKey4=testValue4';
var exists = (0, index_1.hasCookie)('testKey4');
expect(exists).toBe(true);
});
test('hasCookie should return false for non-existing cookie', function () {
var exists = (0, index_1.hasCookie)('nonExistentKey5');
expect(exists).toBe(false);
});
test('getCookie should return undefined for non-existing cookie', function () {
var value = (0, index_1.getCookie)('nonExistentKey');
expect(value).toBeUndefined();
});
test('setCookie should handle complex values', function () {
var complexValue = { key: 'value', nested: { array: [1, 2, 3] } };
(0, index_1.setCookie)('complexKey', complexValue);
var retrievedValue = (0, index_1.getCookie)('complexKey');
expect(typeof retrievedValue === 'string' ? JSON.parse(retrievedValue) : {}).toEqual(complexValue);
});
});