Replies: 2 comments
-
Fabulous. I just started writing tests for something like this today. Really eager to see the discussion. For context, I'm testing authentication code and I want to make sure it correctly throws or returns data and/or redirects. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Is it just typescript errors you are running into? If so maybe this assert function that we use in a fully future flagged & single fetched Remix v2 app should help, since it should be similar to RR7. export function assertIsDataWithResponseInit(
response: unknown
): asserts response is {
init: ResponseInit | null;
data: unknown;
type: string;
} {
if (
typeof response === "object" &&
response != null &&
"type" in response &&
"data" in response &&
"init" in response &&
response.type === "DataWithResponseInit"
) {
return;
}
throw new Error("Expected DataWithResponseInit");
} Usage: const response = await action({
request: request,
params: {},
context: {}
});
assertIsDataWithResponseInit(response);
expect(response.data).toStrictEqual({
message: {
description: "An error occurred. Please try again later.",
},
}); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi there,
I have just migrated one of my web app from Remix v2 to React Router 7 (framework). Everything seems to work as expected, but I have problems with testing loaders and actions. Basic idea how to test loaders an actions in Remix I have found on this article/tutorial from Sergio:
https://sergiodxa.com/tutorials/test-remix-loaders-and-actions
But it doesn't hold anymore because loaders and actions in React Router 7 return:
So we cannot just use res.json() or res.status() or something like: expect(res).toBeInstanceOf(Response);
How to test it in RR7?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions