algolia / faux-jax

NO MORE MAINTAINED: Intercept and respond to requests in the browser (AJAX) and Node.js (http(s) module)
MIT License
95 stars 10 forks source link

faux-jax: received an unexpected request #19

Open mildfuzz opened 8 years ago

mildfuzz commented 8 years ago

I am getting the error faux-jax: received an unexpected request

It's confusing because the stack is not pointing to any of my code, and as far as I can tell ALL requests should be expected.

vvo commented 8 years ago

Hi, to further debug this with you we need some more context:

Thanks

mildfuzz commented 8 years ago

It's in a Jasmine spec, not in algolia module.

I am struggling to pin what exactly is causing it, but am I wrong in thinking that all requests should be expected, and I do not need to register a request ahead of time.

vvo commented 8 years ago

You need to register to request ahead of time, this is done so that you explicitly expect for requests rather than having some requests being done while you were not listening.

mildfuzz commented 8 years ago

The examples on the front page make it appear that we do not need to specify a path or a domain, just that we want to intercept (fauxJax.install) On Wed, 22 Jun 2016 at 14:39, Vincent Voyer notifications@github.com wrote:

You need to register to request ahead of time, this is done so that you explicitly expect for requests rather than having some requests being done while you were not listening.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/algolia/faux-jax/issues/19#issuecomment-227746310, or mute the thread https://github.com/notifications/unsubscribe/AAMAYWvSFXBD7PBdxvgugA1A93ye5vGyks5qOTscgaJpZM4I7rcL .

vvo commented 8 years ago

Yes once you install, everything is captured

mildfuzz commented 8 years ago

so assuming I have done that before any tests run (which I have), what other conditions could lead to this errror being triggered?

vvo commented 8 years ago

what other conditions could lead to this errror being triggered?

Well it means somewhere you got a request you were not listening for, for example if you use waitFor(3) and 4 requests are coming, or if you do .once('request') and another one is coming.

Other than that, I don't know, maybe dig inside your code and debug it. Without any reproducing code that's hard to solve, sorry

mildfuzz commented 8 years ago

hmm, not using either of those methods :/

mildfuzz commented 8 years ago

If I comment out line 68 of index.js

//this.emit('error', new Error('faux-jax: received an unexpected request: ' + req.headers.host + req.url));

I get a string of fauxJax.remove is not a function which makes me think that it is not installed correctly.

If I simply install once (rather than beforeEach) and don't use remove, then my jasmine spec passes, albeit with a memory leak warning which i did not have before.

Does any of that mean anything to you?

mildfuzz commented 8 years ago

Okay, so that was me being dopey. I was using remove instead of restore.

The first half of that comment still stands. I need to remove that error in order for my tests to pass, which they all do

vvo commented 8 years ago

Sorry I fail to see if you are still having an issue?

mildfuzz commented 8 years ago

My tests pass, but only if I comment out line 68 of the fauxJax index.js

vvo commented 8 years ago

To easily solve this now we need a repo where we can reproduce the problem.

mildfuzz commented 8 years ago

I fixed this issue by disabling the errors. Currently I am building from my own fork, but would prefer to pull back into the project. Is it worth making the errors a config option?

vvo commented 8 years ago

I will accept a PR adding an option like "allowUnexpectedRequests"