I'm relatively new to programming and have never written tests. I want to write unit tests for a group project (Angular web app with node background environment written in typescript), which you can find here. I picked out an examples which I want to test and I hope with your answers I can transfer what I learn to other parts of the project. Here is the piece of code in authentication.ts
:
import {Request, Response} from 'express';
export function authenticatedUser(req: Request, res: Response, next: Function) {
if (!req.user) {
res.statusCode = 403;
res.send('You are not logged in.');
}
next();
}
I would like to write a unit test with Jasmine and run it with Karma in the web browser. My file authentication.spec.ts
looks like this right now:
import jasmine;
import { authenticatedUser } from './authentication'
describe("authentication", () => {
it("should authenticate user", () => {
expect().toBE();
});
});
I don't know how to proceed and if there is an if
statement, do I need to test for true
and false
?