|
1 | 1 | import flushPromises from 'flush-promises';
|
2 | 2 | import { afterEach, describe, expect, it, vi } from 'vitest';
|
3 |
| -import { ref } from 'vue'; |
| 3 | +import { isProxy, isRef, ref } from 'vue'; |
4 | 4 | import * as PowerSync from '../src/composables/powerSync';
|
5 | 5 | import { useQuery } from '../src/composables/useQuery';
|
6 | 6 | import { withSetup } from './utils';
|
@@ -61,6 +61,21 @@ describe('useQuery', () => {
|
61 | 61 | expect(error.value).toEqual(undefined);
|
62 | 62 | });
|
63 | 63 |
|
| 64 | + // ensure that Proxy wrapper object is stripped |
| 65 | + it('should propagate raw reactive sql parameters', async () => { |
| 66 | + vi.spyOn(PowerSync, 'usePowerSync').mockReturnValue(ref(mockPowerSync) as any); |
| 67 | + const getAllSpy = mockPowerSync.getAll; |
| 68 | + |
| 69 | + const [{ data, isLoading, isFetching, error }] = withSetup(() => |
| 70 | + useQuery('SELECT * from lists where id = $1', ref([ref('test')])) |
| 71 | + ); |
| 72 | + await flushPromises(); |
| 73 | + expect(getAllSpy).toHaveBeenCalledTimes(1); |
| 74 | + const sqlParam = (getAllSpy.mock.calls[0] as Array<any>)[1]; |
| 75 | + expect(isRef(sqlParam)).toEqual(false); |
| 76 | + expect(isProxy(sqlParam)).toEqual(false); |
| 77 | + }); |
| 78 | + |
64 | 79 | it('should rerun the query when refresh is used', async () => {
|
65 | 80 | vi.spyOn(PowerSync, 'usePowerSync').mockReturnValue(ref(mockPowerSync) as any);
|
66 | 81 | const getAllSpy = mockPowerSync.getAll;
|
@@ -132,7 +147,7 @@ describe('useQuery', () => {
|
132 | 147 | it('should set error for compilable query on useQuery parameters', async () => {
|
133 | 148 | vi.spyOn(PowerSync, 'usePowerSync').mockReturnValue(ref(mockPowerSync) as any);
|
134 | 149 |
|
135 |
| - const [{ isLoading, error }] = withSetup(() => |
| 150 | + const [{ error }] = withSetup(() => |
136 | 151 | useQuery({ execute: () => [] as any, compile: () => ({ sql: 'SELECT * from lists', parameters: [] }) }, ['x'])
|
137 | 152 | );
|
138 | 153 |
|
|
0 commit comments