So right now I have something like this (which doesn't work)
import app from '../src/app';
beforeAll(() =>
jest.mock('../src/middleware/auth', () => (req: Request, res: Response, next: NextFunction) => {
req.user = {};
return next();
});
afterAll(() =>
jest.unmock('../src/middleware/auth'));
and then my test as usual:
describe('POST /v1/protected-route', () => {
it('should return 200 OK', async () => {
await request(app)
.get('/v1/protected-route')
...
in ../src/app
I'm importing ./middleware/auth
and adding it like so app.use(auth())
I still keep getting 401s and it looks like the mock is not getting used here.