#how to unit test for POST/PUT using Deno.test

1 messages · Page 1 of 1 (latest)

astral socket
#

I am trying to unit test a Deno edge function and i am a little confused by the docs. createMockContext has no option to pass a body . how do i test for POST and PUT?

import { testing } from "https://deno.land/x/oak/mod.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";
import {
  getAllContacts,
  getContactById,
  createContact,
  updateContact,
  deleteContact,
} from "../_controllers/contactMeController.ts";

Deno.test({
    name: 'Call createContact function',
    async fn() {
        const ctx = testing.createMockContext({
            path: '/contact',
            body???????            
        });

        const response = await createContact(ctx);
        assertEquals(ctx.response.status, 201);
    },
});
muted ginkgo
#

I had the exact same question the other day. Don’t know. But I found superoak which might help, haven’t tested it yet.