dero icon indicating copy to clipboard operation
dero copied to clipboard

Unit / Integration test with Dero

Open shinspiegel opened this issue 1 year ago • 1 comments

This framework looks like there is a lot of batteries already included, but I didn't saw any way for testing this framework,

How can I unit or integrate test with this framework?

shinspiegel avatar Apr 04 '23 08:04 shinspiegel

Thanks for creating issue. I think superdeno is a great library for testing the Rest API. below example with Dero.

import { BaseController, Controller, Dero, Get } from "https://deno.land/x/[email protected]/mod.ts";
import { superdeno } from "https://deno.land/x/[email protected]/mod.ts";

@Controller("/user")
class UserController extends BaseController {
  @Get()
  getUser() {
    return "Hello";
  }
}

class Application extends Dero {
  constructor() {
    super();
    this.use({ class: [UserController] });
  }
}

const app = new Application();
const handle = (request: Request) => app.handleEvent({ request });

Deno.test("Test App", async () => {
  await superdeno(handle)
    .get("/user")
    .expect("Hello");
});

Run :

deno test -A app_test.ts

herudi avatar Apr 05 '23 05:04 herudi