-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
bigBoi.test.tsx
63 lines (54 loc) · 1.59 KB
/
bigBoi.test.tsx
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { appRouter } from '../__generated__/bigBoi/_app';
import { getServerAndReactClient } from './__reactHelpers';
import { render, waitFor } from '@testing-library/react';
import { expectTypeOf } from 'expect-type';
import { konn } from 'konn';
import React from 'react';
const ctx = konn()
.beforeEach(() => {
return getServerAndReactClient(appRouter);
})
.afterEach(async (ctx) => {
await ctx?.close?.();
})
.done();
test('vanilla', async () => {
const { opts } = ctx;
const { proxy } = opts;
{
const result = await proxy.r0.greeting.query({ who: 'KATT' });
expect(result).toBe('hello KATT');
expectTypeOf(result).not.toBeAny();
expectTypeOf(result).toMatchTypeOf<string>();
}
{
const result = await proxy.r10.grandchild.grandChildMutation.mutate();
expect(result).toBe('grandChildMutation');
}
{
const result = await proxy.r499.greeting.query({ who: 'KATT' });
expect(result).toBe('hello KATT');
expectTypeOf(result).not.toBeAny();
expectTypeOf(result).toMatchTypeOf<string>();
}
});
test('useQuery()', async () => {
const { proxy, App } = ctx;
function MyComponent() {
const query1 = proxy.r499.greeting.useQuery({ who: 'KATT' });
if (!query1.data) {
return <>...</>;
}
expectTypeOf(query1.data).not.toBeAny();
expectTypeOf(query1.data).toMatchTypeOf<string>();
return <pre>{JSON.stringify(query1.data ?? 'n/a', null, 4)}</pre>;
}
const utils = render(
<App>
<MyComponent />
</App>,
);
await waitFor(() => {
expect(utils.container).toHaveTextContent(`hello KATT`);
});
});