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
|
|
|
|
2023-04-02 18:26:24 +08:00
|
|
|
describe('src/helpers/combineURL.ts', () => {
|
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');
|
|
|
|
});
|
|
|
|
|
2023-04-23 23:05:30 +08:00
|
|
|
test('应该直接返回第二个参数', () => {
|
|
|
|
expect(combineURL('', 'http://api.com')).toBe('http://api.com');
|
|
|
|
expect(combineURL('', 'file://api.com')).toBe('file://api.com');
|
|
|
|
});
|
|
|
|
|
2023-04-01 23:11:55 +08:00
|
|
|
test('应该得到拼接后的结果', () => {
|
2023-04-05 08:40:00 +08:00
|
|
|
expect(combineURL('http://api.com', 'test')).toBe('http://api.com/test');
|
2023-04-25 15:06:19 +08:00
|
|
|
expect(combineURL('http://api.com/', 'test')).toBe('http://api.com/test');
|
|
|
|
expect(combineURL('http://api.com', '/test')).toBe('http://api.com/test');
|
|
|
|
expect(combineURL('http://api.com/', '/test')).toBe('http://api.com/test');
|
2023-04-01 23:11:55 +08:00
|
|
|
});
|
|
|
|
|
2023-04-25 15:06:19 +08:00
|
|
|
test('应该保留末尾自带的斜线', () => {
|
|
|
|
expect(combineURL('http://api.com/', '')).toBe('http://api.com/');
|
|
|
|
expect(combineURL('http://api.com', '/')).toBe('http://api.com/');
|
|
|
|
expect(combineURL('http://api.com/', '/')).toBe('http://api.com/');
|
|
|
|
expect(combineURL('http://api.com', 'test/')).toBe('http://api.com/test/');
|
2023-04-01 23:11:55 +08:00
|
|
|
});
|
|
|
|
});
|