data-mocks icon indicating copy to clipboard operation
data-mocks copied to clipboard

Matching http request are passing

Open Tabris841 opened this issue 7 years ago • 7 comments

Hi,

First of all i love the idea of the library. Great Job guys!!!. I wanted to include the the library in my project, but i don't want to mock every request so i set MockConfig allowXHRPassthrough and allowFetchPassthrough to true. And the problem is every request is passing even when there is matching route and when there is response then data-mocks replace the response. Is that intended behaviour and can the requests be intercept when they match before sending(cause for example i want to mock and endpoint before is created)?

To Reproduce Just create angular project the cli and add data-mock. Set the allowXHRPassthrough and allowFetchPassthrough to true Create some scenario(example: { url: /users/, method: 'GET', response: { some: 'good response' }, responseCode: 200 }) Make a http call to that scenario(example: ''http://localhost:3000/api/users')

Tabris841 avatar Oct 15 '19 07:10 Tabris841

Hey @Tabris841 - two things!

  1. I'm so so so so sorry I didn't get back to you on this any sooner. I've been on leave with my newborn so I haven't had time to throw at data-mocks until now as I'm back in action!
  2. Thank you so much for bringing this issue up. I'll work on a fix for it this week :)

-Dave

grug avatar Nov 19 '19 08:11 grug

Just dropping by to inform you I have the same problem.

mpoelstra avatar Nov 21 '19 11:11 mpoelstra

I'm still planning on fixing this tomorrow :) Hopefully it'll be released then, too!

grug avatar Nov 21 '19 11:11 grug

Current workaround is to use XHRMock proxy directly after injectMocks

  injectMocks(scenarios, undefined, {
    // allowXHRPassthrough: true,
  });
  XHRMock.use(proxy);

LaserUnicorns avatar Nov 21 '19 12:11 LaserUnicorns

Sweet - a fix is in master and I've checked it out and it's good. I'll make a release now.

grug avatar Nov 21 '19 13:11 grug

Version 2.5.13 is out now and should make everything all good. Let me know if you have any other questions/problems :) Once again, so sorry for taking so long to getting this one sorted!

grug avatar Nov 21 '19 13:11 grug

Sweet! Works like a charm, thx! And don't be sorry, taking care for your newborn is far more important ;)

mpoelstra avatar Nov 21 '19 14:11 mpoelstra