axios-miniprogram/test/helpers/combineURL.test.ts

37 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-04-01 23:11:55 +08:00
import { describe, test, expect } from 'vitest';
2023-04-10 22:53:15 +08:00
import { combineURL } from '@/helpers/combineURL';
2023-04-01 23:11:55 +08:00
describe('src/helpers/combineURL.ts', () => {
2023-04-10 22:53:15 +08:00
test('应该支持空参数', () => {
expect(combineURL()).toBe('');
expect(combineURL('')).toBe('');
expect(combineURL(undefined, '')).toBe('');
});
2023-04-01 23:11:55 +08:00
test('应该直接返回第一个参数', () => {
expect(combineURL('http://api.com', '')).toBe('http://api.com');
expect(combineURL('file://api.com', '')).toBe('file://api.com');
expect(combineURL('unknow://api.com', '')).toBe('unknow://api.com');
});
test('应该得到拼接后的结果', () => {
2023-04-05 08:40:00 +08:00
expect(combineURL('http://api.com', 'test')).toBe('http://api.com/test');
2023-04-03 21:03:33 +08:00
expect(combineURL('file://api.com', '/test')).toBe('file://api.com/test');
expect(combineURL('unknow://api.com', '/test')).toBe(
'unknow://api.com/test',
2023-04-01 23:11:55 +08:00
);
});
test('应该清理多余的斜线', () => {
2023-04-07 08:47:54 +08:00
expect(combineURL('//api//', 'test//')).toBe('/api/test');
expect(combineURL('//api//', '//test//')).toBe('/api/test');
expect(combineURL('////', '')).toBe('');
expect(combineURL('', '///')).toBe('');
expect(combineURL('http://api.com//', '')).toBe('http://api.com');
expect(combineURL('http://api.com/', '/')).toBe('http://api.com');
2023-04-03 21:03:33 +08:00
expect(combineURL('http://api.com//', '//test//')).toBe(
2023-04-07 08:47:54 +08:00
'http://api.com/test',
2023-04-01 23:11:55 +08:00
);
});
});