How to add routes in my spec file to prevent route pollution in my routing files while testing jwt authentication levels?

Route file (routes/api.js):

const express = require('express');
const passport = require('passport');
const router = express.Router();
const SteamApp = require('../models/steamapp.model');
const SteamAPI = require('../lib/steam.lib');

router.use((req, res, next) => {
  passport.authenticate('jwt', { session: false } )(req, res, next);
} );

router.get('/getwishlist', async function(req, res, next) {
  // return appropriate data
} );

// [...] Other routes

Which is integrated by calling app.use('/api', require('./routes/api'));.

Inside one of my spec file, I want to test that the jwt authentication works properly and respects the different access levels available. So certain routes are available to certain users and all routes require the user to authenticate. This is not the part where I test existing routes themselves.

To make sure that nothing is inadvertently created, updated or deleted and that remote APIs are not called, I need to create additional routes, such as /api/test, /api/testuser, /api/testadmin and so forth. I know I could create the routes inside my api.js file but that would be polluting the file.

Here is my spec file:

const app = require('../app');
const request = require('supertest');
const jwt = require('jsonwebtoken');
const crypto = require('crypto');
const JWT_TOKEN = process.env.JTW_KEY;

const regularUser = {
  // user data
}

const notAUser = {
  // Fake user data
}

describe("Authentification JWT", () => {
  afterAll(async () => {
    const mongoose = require('mongoose');
    await mongoose.connection.close();
    await mongoose.disconnect();
  } );

  it("doit permettre la connexion si un jeton correct est donné", async () => {
    const userToken = jwt.sign(regularUser, JWT_TOKEN, { algorithm: 'HS256' });
    const response = await request(app).get('/api/test').set('Authorization', `Bearer ${userToken}`);
    expect(response.statusCode).toBe(200);
  } );

  it("doit refuser la connexion si un jeton incorrect est donné", async () => {
    const userToken = crypto.randomBytes(32).toString('hex');
    const response = await request(app).get('/api/test').set('Authorization', `Bearer ${userToken}`);
    expect(response.statusCode).toBe(401);
  } );

  it("doit refuser la connexion si aucun jeton n'est donné", async () => {
    const response = await request(app).get('/api/test');
    expect(response.statusCode).toBe(401);
  } );

  // Include other tests
} );

How can I add my test specific routes inside a beforeAll function? I have tried the following but requests keep timing out:

beforeAll(() => {
  app.use('/api', (req, res, next) => {
    const router = require ('../routes/api.js');
    router.get('/api/test', function(res, req, next) {
      res.json({ success: true, result: 1, textResult: 'All ok' });
    } );
  } );
} );

The specific error message I get is:

Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)