url.test.ts 676 B

12345678910111213141516171819202122232425
  1. import { toUrlParams } from '../utils/url';
  2. describe('toUrlParams', () => {
  3. it('should encode object properties as url parameters', () => {
  4. const url = toUrlParams({
  5. server: 'backend-01',
  6. hasSpace: 'has space',
  7. many: ['1', '2', '3'],
  8. true: true,
  9. number: 20,
  10. isNull: null,
  11. isUndefined: undefined,
  12. });
  13. expect(url).toBe('server=backend-01&hasSpace=has%20space&many=1&many=2&many=3&true&number=20&isNull=&isUndefined=');
  14. });
  15. });
  16. describe('toUrlParams', () => {
  17. it('should encode the same way as angularjs', () => {
  18. const url = toUrlParams({
  19. server: ':@',
  20. });
  21. expect(url).toBe('server=:@');
  22. });
  23. });