Skip to content

How to use trpc directly in playwright testing? #123

@WhyAsh5114

Description

@WhyAsh5114

Describe the bug
Unable to use trpc client in playwright tests

To Reproduce
Steps to reproduce the behavior:

  1. Setup a sveltekit project with playwright enabled
  2. Create a basic tRPC config with an endpoint
  3. Try to directly call it from playwright

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:

  1. I tried using it without args and it gave me an
    Calling createTRPCClient() on the server requires passing a valid LoadEvent argument
  2. Maybe I'm supposed to use createCaller() with createContext() like we do in server load functions, but what do we pass to the createContext()?
  3. Creating the client with { url: { origin: page.url() } } also doesn't seem to work and give this error:
    TRPCClientError: Unexpected token '<', "<!doctype "... is not valid JSON

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions