优化
This commit is contained in:
41
client/shared/utils/__tests__/string-helper.spec.ts
Normal file
41
client/shared/utils/__tests__/string-helper.spec.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { isAvailableString, isObjectId, isUrl } from '../string-helper';
|
||||
|
||||
describe('string-helper', () => {
|
||||
describe('isAvailableString', () => {
|
||||
test.each<[any, boolean]>([
|
||||
['any string', true],
|
||||
['', false],
|
||||
[1, false],
|
||||
[() => {}, false],
|
||||
[{}, false],
|
||||
[[], false],
|
||||
[undefined, false],
|
||||
[null, false],
|
||||
])('%p => %p', (url, res) => {
|
||||
expect(isAvailableString(url)).toBe(res);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isUrl', () => {
|
||||
test.each<[string, boolean]>([
|
||||
['http://baidu.com', true],
|
||||
['https://baidu.com', true],
|
||||
['ws://baidu.com', true],
|
||||
['wss://baidu.com', true],
|
||||
['baidu.com', false],
|
||||
['baidu', false],
|
||||
])('%s => %p', (url, res) => {
|
||||
expect(isUrl(url)).toBe(res);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isObjectId', () => {
|
||||
test.each<[string, boolean]>([
|
||||
['1', false],
|
||||
['unknown', false],
|
||||
['64b4a473a44c273805b25da5', true],
|
||||
])('%s => %p', (input, res) => {
|
||||
expect(isObjectId(input)).toBe(res);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user