Matt Thompson
Matt Thompson
TtRPC
Created by Matt Thompson on 4/26/2023 in #❓-help
Mocking tRPC call w/ Playwright (Transform Error)
Thanks for the 👀 and help @Nick Lucas
18 replies
TtRPC
Created by Matt Thompson on 4/26/2023 in #❓-help
Mocking tRPC call w/ Playwright (Transform Error)
Worked 🙂 End Result for me:
await page.route('**/api/trpc/onboarding.verifyPrimaryPractice?batch=1', (route) => {
route.fulfill({
status: 200,
body: JSON.stringify([
{ result: { data: { json: { success: true } }, meta: { values: {} } } },
]),
headers: { 'Content-Type': 'application/json' },
});
});
await page.route('**/api/trpc/onboarding.verifyPrimaryPractice?batch=1', (route) => {
route.fulfill({
status: 200,
body: JSON.stringify([
{ result: { data: { json: { success: true } }, meta: { values: {} } } },
]),
headers: { 'Content-Type': 'application/json' },
});
});
In this case I don't really care about the return - I simply want it to keep going But you could mock out the full return under data.json here. The way the tests run, I shouldn't have more than one for batch
18 replies
TtRPC
Created by Matt Thompson on 4/26/2023 in #❓-help
Mocking tRPC call w/ Playwright (Transform Error)
Ah, Yea For the most part we are doing that with Factories, etc. This call has a 3rd party call where I don't have a Sandbox to run against. I was originally looking for the equiv of Jest.mock in Playwright E2E The closest thing they support is Network mocking Sadly the 3rd party call couldn't be mocked in this scenario as the tRPC call is calling it within Fun edge case I guess. I'm looking at the real result like you mentioned above and trying to mock the array. I didn't take that into account earlier. 🤞
18 replies
TtRPC
Created by Matt Thompson on 4/26/2023 in #❓-help
Mocking tRPC call w/ Playwright (Transform Error)
Looking at the above. Do you mind expanding on this a bit? " We would generally recommend you bring your API under test with tRPC.
18 replies
TtRPC
Created by Matt Thompson on 4/26/2023 in #❓-help
Mocking tRPC call w/ Playwright (Transform Error)
Correct, we are using trpc client below on the form submit. I'm trying to stub that call out. Outside of the transform piece - it seems to be working as expected. I'm just unsure why the transform fails.
const verifyPractice = trpc.onboarding.verifyPrimaryPractice.useMutation({
onSuccess: () => {...}
onError: () => {...}
})

...

const handleOnSubmit = async (data) => await verifyPractice.mutateAsync(data);
const verifyPractice = trpc.onboarding.verifyPrimaryPractice.useMutation({
onSuccess: () => {...}
onError: () => {...}
})

...

const handleOnSubmit = async (data) => await verifyPractice.mutateAsync(data);
18 replies