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);
});
});