Serialize and deserialize data.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

x-www-form-urlencoded.test.ts 1.1 KiB

12345678910111213141516171819202122232425262728293031323334
  1. import { describe, expect, it } from 'vitest';
  2. import { deserialize, serialize } from '../../src/types/application/x-www-form-urlencoded';
  3. describe('application/x-www-form-urlencoded', () => {
  4. describe('serialize', () => {
  5. it('should throw when serializing a string', () => {
  6. expect(() => serialize('Hello, World!')).toThrow();
  7. });
  8. it('should throw when serializing a number', () => {
  9. expect(() => serialize(123)).toThrow();
  10. });
  11. it('should throw when serializing a boolean', () => {
  12. expect(() => serialize(true)).toThrow();
  13. });
  14. it('should throw when serializing an array', () => {
  15. expect(() => serialize([1, 2, 3])).toThrow();
  16. });
  17. it('should serialize an object', () => {
  18. const result = serialize({ a: 1, b: 2, c: 3 });
  19. expect(result).toBe('a=1&b=2&c=3');
  20. });
  21. });
  22. describe('deserialize', () => {
  23. it('should deserialize an object', () => {
  24. const result = deserialize<{ a: string, b: string, c: string }>('a=1&b=2&c=3');
  25. expect(result).toEqual({ a: '1', b: '2', c: '3' });
  26. });
  27. });
  28. });