Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Minor nits in the docs folder #107

Merged
merged 4 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions backend/docs/testing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Testing

## Introduction

[Mocha](https://github.com/mochajs/mocha) and [Jest](https://github.com/jestjs/jest) were considered as testing frameworks. Jest was chosen, because it is more commonly used and the team was more familiar with it. NestJS, which is used as the backend framework, also uses jest for testing by default.

## Getting started

<https://jestjs.io/docs/getting-started>
<https://docs.nestjs.com/fundamentals/testing#unit-testing>

## Conventions

Tests should be defined in a `test` folder in both the frontend and backend directories. Unit test files use the file ending `.spec.ts`. End to end tests use the `.e2e-spec.ts` file ending.

For unit tests we use the assertions provided by Jest. For end to end tests we use [`supertest`](https://github.com/ladjs/supertest).

## Example Unit Test

```ts
import { CatsController } from './cats.controller';
import { CatsService } from './cats.service';

describe('CatsController', () => {
let catsController: CatsController;
let catsService: CatsService;

beforeEach(() => {
catsService = new CatsService();
catsController = new CatsController(catsService);
});

describe('findAll', () => {
it('should return an array of cats', async () => {
const result = ['test'];
jest.spyOn(catsService, 'findAll').mockImplementation(() => result);

expect(await catsController.findAll()).toBe(result);
});
});
});
```

## Example End to End Test

```ts
import * as request from 'supertest';
import { Test } from '@nestjs/testing';
import { CatsModule } from '../../src/cats/cats.module';
import { CatsService } from '../../src/cats/cats.service';
import { INestApplication } from '@nestjs/common';

describe('Cats', () => {
let app: INestApplication;
let catsService = { findAll: () => ['test'] };

beforeAll(async () => {
const moduleRef = await Test.createTestingModule({
imports: [CatsModule],
})
.overrideProvider(CatsService)
.useValue(catsService)
.compile();

app = moduleRef.createNestApplication();
await app.init();
});

it(`/GET cats`, () => {
return request(app.getHttpServer()).get('/cats').expect(200).expect({
data: catsService.findAll(),
});
});

afterAll(async () => {
await app.close();
});
});
```
Binary file removed docs/01-requirements/anforderungen.pdf
Binary file not shown.
208 changes: 0 additions & 208 deletions docs/01-requirements/anforderungen.typ

This file was deleted.

Binary file not shown.
Loading
Loading