aboutsummaryrefslogtreecommitdiff
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/astro/src/actions/runtime/route.ts2
-rw-r--r--packages/astro/test/actions.test.js28
-rw-r--r--packages/astro/test/fixtures/actions/src/actions/index.ts10
3 files changed, 39 insertions, 1 deletions
diff --git a/packages/astro/src/actions/runtime/route.ts b/packages/astro/src/actions/runtime/route.ts
index d5bdf2f89..463a4ac6e 100644
--- a/packages/astro/src/actions/runtime/route.ts
+++ b/packages/astro/src/actions/runtime/route.ts
@@ -40,7 +40,7 @@ export const POST: APIRoute = async (context) => {
);
}
return new Response(JSON.stringify(result.data), {
- status: result.data ? 200 : 204,
+ status: result.data !== undefined ? 200 : 204,
headers: {
'Content-Type': 'application/json',
},
diff --git a/packages/astro/test/actions.test.js b/packages/astro/test/actions.test.js
index 279493a12..a4322b186 100644
--- a/packages/astro/test/actions.test.js
+++ b/packages/astro/test/actions.test.js
@@ -228,5 +228,33 @@ describe('Astro Actions', () => {
assert.equal($('[data-url]').text(), '/subscribe');
assert.equal($('[data-channel]').text(), 'bholmesdev');
});
+
+ it('Returns content when the value is 0', async () => {
+ const req = new Request('http://example.com/_actions/zero', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Content-Length': '0',
+ },
+ });
+ const res = await app.render(req);
+ assert.equal(res.status, 200);
+ const value = await res.json();
+ assert.equal(value, 0);
+ });
+
+ it('Returns content when the value is false', async () => {
+ const req = new Request('http://example.com/_actions/false', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Content-Length': '0',
+ },
+ });
+ const res = await app.render(req);
+ assert.equal(res.status, 200);
+ const value = await res.json();
+ assert.equal(value, false);
+ });
});
});
diff --git a/packages/astro/test/fixtures/actions/src/actions/index.ts b/packages/astro/test/fixtures/actions/src/actions/index.ts
index 62b1f01ba..03de31d0c 100644
--- a/packages/astro/test/fixtures/actions/src/actions/index.ts
+++ b/packages/astro/test/fixtures/actions/src/actions/index.ts
@@ -64,4 +64,14 @@ export const server = {
return;
}
}),
+ zero: defineAction({
+ handler: async () => {
+ return 0;
+ }
+ }),
+ false: defineAction({
+ handler: async () => {
+ return false;
+ }
+ })
};