Created
October 8, 2022 17:48
-
-
Save barisbll/cefef791cb7bf53b0663582ee076a2bc to your computer and use it in GitHub Desktop.
Test file example with our new jest setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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