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

36 lines
911 B
TypeScript
Raw Normal View History

import { describe, test, expect } from 'vitest';
2023-04-10 22:53:15 +08:00
import { dynamicURL } from '@/helpers/dynamicURL';
describe('src/helpers/dynamicURL.ts', () => {
test('应该替换关键字', () => {
2023-04-03 21:03:33 +08:00
expect(dynamicURL('http://api.com/test/:id', {})).toBe(
'http://api.com/test/undefined',
);
2023-04-03 21:03:33 +08:00
expect(dynamicURL('http://api.com/test/:id', { id: 1 })).toBe(
'http://api.com/test/1',
);
});
test('应该支持多个关键字', () => {
expect(
2023-04-03 21:03:33 +08:00
dynamicURL('http://api.com/tests/name/:name/type/:type/list', {
name: 'axios',
type: 0,
}),
2023-04-03 21:03:33 +08:00
).toBe('http://api.com/tests/name/axios/type/0/list');
});
test('应该忽略端口号', () => {
expect(
dynamicURL(':8080/:id', {
id: 0,
}),
).toBe(':8080/0');
expect(
dynamicURL('http://api.com:8080/:id', {
id: 0,
}),
).toBe('http://api.com:8080/0');
});
});