Testing

Testing your application is a very important aspect of building safe applications. Entropy leverages the power of built-in Deno testing APIs to create a flawless testing experience.

Writing Tests

All test files end with .test.ts. They are typically placed eather in app modules or in the /tests directory.

Writing tests is very intuitive and simple. All you need is basically the built-in Deno testing API.

      

src/root.test.ts

import { expect } from '@std/expect/expect.ts'; import { fetchRoute } from '@entropy/testing'; import { HttpStatus } from '@entropy/http'; import { RootController } from './root.controller.ts'; Deno.test('root module', async (test) => { await test.step('root controller returns a proper home page', async () => { const { body, statusCode } = await fetchRoute('/', RootController); expect(body).toContain('Hello, world!'); expect(statusCode).toBe(HttpStatus.Ok); }); });

As you can see, all you need is to define test cases and their steps. For testing routes and controllers, use Entropy's fetchRoute function.

Running Tests

To check if your tests are passing, run the following Deno task:

      

terminal

deno task test

And you should see the following message:

      

terminal

ok | 1 passed (1 step) | 0 failed (6ms)
Utilities