File size: 999 Bytes
bf48b89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { describe, expect, it, vi } from 'vitest';

import getWrappedGet from '@/utils/request-rewriter/get';

describe('request-rewriter get wrapper', () => {
    it('passes callback when url and callback are provided', () => {
        const origin = vi.fn(() => 'ok');
        const wrapped = getWrappedGet(origin as any);
        const callback = vi.fn();

        const result = wrapped('http://example.com/test', callback);

        expect(result).toBe('ok');
        expect(origin).toHaveBeenCalledTimes(1);
        expect(origin.mock.calls[0][2]).toBe(callback);
    });

    it('falls back to origin when url parsing fails', () => {
        const origin = vi.fn(() => 'fallback');
        const wrapped = getWrappedGet(origin as any);
        const callback = vi.fn();
        const options = { href: 'http://' } as any;

        const result = wrapped(options, callback);

        expect(result).toBe('fallback');
        expect(origin).toHaveBeenCalledWith(options, callback);
    });
});