Open WhyAsh5114 opened 3 months ago
Playwright runs in a node environment, so you are unable to create a browser trpc client with trpc-sveltekit
. It is missing the necessary context to know where to send the requests.
If you want to test your endpoint, you will need to manually create a client with @trpc/client
and pass in where your web server is running.
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
const client = createTRPCProxyClient({
links: [httpBatchLink({ url: "..." })],
});
I tried this too, the method returns a weird string union
Describe the bug Unable to use trpc client in playwright tests
To Reproduce Steps to reproduce the behavior:
Expected behavior The client should work as it does in Svelte files in the frontend
Additional context I tried various methods to create the client in playwright:
Calling createTRPCClient() on the server requires passing a valid LoadEvent argument
createCaller()
withcreateContext()
like we do in server load functions, but what do we pass to thecreateContext()
?{ url: { origin: page.url() } }
also doesn't seem to work and give this error:TRPCClientError: Unexpected token '<', "<!doctype "... is not valid JSON