|
| 1 | +/* eslint-disable max-lines */ |
1 | 2 | import axios from 'axios';
|
2 | 3 | import nock from 'nock';
|
3 | 4 | import { expect, it, describe, beforeEach, vi } from 'vitest';
|
4 | 5 | import { defineProxy } from '../src';
|
5 | 6 |
|
6 | 7 | const BASE_URL = 'https://api.com.br';
|
7 |
| -function to(promise: Promise<unknown>) { |
8 |
| - return promise |
9 |
| - .then(value => [undefined, value]) |
10 |
| - .catch(error => [error, undefined]); |
| 8 | +async function to(promise: Promise<unknown>) { |
| 9 | + try { |
| 10 | + const value = await promise; |
| 11 | + return [undefined, value]; |
| 12 | + } catch (error) { |
| 13 | + return [error, undefined]; |
| 14 | + } |
11 | 15 | }
|
12 | 16 |
|
13 | 17 | describe('axios-dev-proxy tests', () => {
|
@@ -212,6 +216,17 @@ describe('axios-dev-proxy tests', () => {
|
212 | 216 | expect(response2.data).toEqual({ data: 2 });
|
213 | 217 | expect(response2.status).toEqual(201);
|
214 | 218 | });
|
| 219 | + |
| 220 | + it('should modify response for regex route', async () => { |
| 221 | + server.get('/test/2?q=2').reply(200, { data: 1 }); |
| 222 | + |
| 223 | + proxy.onGet(/\/test\/\d+/).replyOnce(201, { |
| 224 | + data: 2, |
| 225 | + }); |
| 226 | + const response = await api.get('/test/2?q=2'); |
| 227 | + expect(response.data).toEqual({ data: 2 }); |
| 228 | + expect(response.status).toEqual(201); |
| 229 | + }); |
215 | 230 | });
|
216 | 231 |
|
217 | 232 | describe('always GET configs', () => {
|
|
0 commit comments