Nock (npm): FetchError due to request mismatch – no route found

Testing our API with intercept reveals a mismatch: expected URL (/endpoint/5) but got (/endpoint/4). See code sample below:

import { initializeServer } from '../sample/serverSetup';
import interceptor from 'nock';

describe('Intercept Mismatch Test', () => {
  let serverInstance;

  beforeAll(async () => {
    serverInstance = await initializeServer();
  });

  it('Verifies correct HTTP endpoint is called', async () => {
    const mockInterceptor = interceptor('https://api.example.org')
      .get('/endpoint/5')
      .reply(200, { key: 'value' });

    const response = await serverInstance.makeRequest('/verify', { method: 'GET' });
    expect(response.status).toBe(200);
    expect(mockInterceptor.isDone()).toBe(true);
  });
});

i think the route mismatch is due to an incorrect api path. check if your actual req is calling /endpoint/4 while intercept expects /endpoint/5. aligning these should fix it.