Files
NapCatQQ/.pnpm-store/v3/files/04/5d0725887aa6a61c4c6b5f5bb39b98e8685ba7237e0d0f15d347694c084d1e7ef248b8d0e409a080994cb287987467423871e6e7fcaa71f2ace874c4b4a271
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

40 lines
1.2 KiB
Plaintext

import { MutableRefObject } from 'react';
import { getUrl } from './get-url';
import { Options } from './types';
let optionRef: MutableRefObject<Options>;
const URL = 'ws://localhost:1234';
const SOCKET_IO_URL = 'http://localhost:1234';
const getUrlAsync = () => {
return new Promise<string>(resolve => {
window.setTimeout(() => {
resolve(URL);
}, 500);
});
};
beforeEach(() => {
optionRef = { current: {} };
});
test('If passed a funtion, it will return a promise that resolves to the return value of the function, after being parsed', async () => {
const wsUrl = await getUrl(getUrlAsync, optionRef);
expect(wsUrl).toEqual(URL);
});
test('If fromSocketIO is passed as an option, socketIO protocol will be used', async () => {
optionRef.current.fromSocketIO = true;
const wsUrl = await getUrl(SOCKET_IO_URL, optionRef);
expect(wsUrl!.endsWith('socket.io/?EIO=3&transport=websocket')).toBe(true);
});
test('If query params are passed in the options, object will be converted to stringified params and appended to url', async () => {
optionRef.current.queryParams = { type: 'user', id: 5 };
const wsUrl = await getUrl(URL, optionRef);
expect(wsUrl!.endsWith('?type=user&id=5')).toBe(true);
});