Skip to content

Commit d384715

Browse files
committed
test: cover server function rejection on 5xx without X-Error
1 parent 0edf76d commit d384715

2 files changed

Lines changed: 34 additions & 0 deletions

File tree

‎apps/tests/cypress/e2e/server-function.cy.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,14 @@ describe("server-function", () => {
5252
cy.visit("/generator-server-function");
5353
cy.get("#server-fn-test").contains('¡Hola, Mundo!');
5454
});
55+
it("should reject the promise when the response is a 5xx without an X-Error header", () => {
56+
cy.intercept("POST", "/_server*", {
57+
statusCode: 500,
58+
headers: { "content-type": "application/json" },
59+
body: { statusCode: 500, statusMessage: "boom" }
60+
});
61+
cy.visit("/server-function-rejected-on-500");
62+
cy.get("#call").click();
63+
cy.get("#server-fn-test").contains("rejected");
64+
});
5565
});
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { createSignal } from "solid-js";
2+
import { serverFnWithIsServer } from "~/functions/use-is-server";
3+
4+
export default function App() {
5+
const [output, setOutput] = createSignal("pending");
6+
7+
const call = async () => {
8+
try {
9+
await serverFnWithIsServer();
10+
setOutput("resolved");
11+
} catch {
12+
setOutput("rejected");
13+
}
14+
};
15+
16+
return (
17+
<main>
18+
<button id="call" onClick={() => void call()}>
19+
call
20+
</button>
21+
<span id="server-fn-test">{output()}</span>
22+
</main>
23+
);
24+
}

0 commit comments

Comments
 (0)