Skip to content

Instantly share code, notes, and snippets.

@barisbll
Created October 8, 2022 17:48
Show Gist options
  • Save barisbll/cefef791cb7bf53b0663582ee076a2bc to your computer and use it in GitHub Desktop.
Save barisbll/cefef791cb7bf53b0663582ee076a2bc to your computer and use it in GitHub Desktop.
Test file example with our new jest setup
import { Request, Response } from 'express';
// eslint-disable-next-line import/no-extraneous-dependencies
import request from 'supertest';
import { Server } from '../../../../../../util/Server';
import { DummyController } from '../Auth.controller';
describe('DummyController', () => {
const dummyController = new AuthController();
describe('getTest', () => {
it('should return a message', () => {
const req = {} as Request;
const res = {
status: jest.fn().mockReturnThis(),
json: jest.fn().mockReturnThis(),
} as unknown as Response;
dummyController.getTest(req, res);
expect(res.status).toHaveBeenCalledWith(200);
expect(res.json).toHaveBeenCalledWith({
message: 'Hello World',
});
});
it('Should send a request using supertest', async () => {
const result = await request(Server.getServer()).get('/api/v1/dummy/test');
expect(result.statusCode).toEqual(200);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment