Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleared mocks are not disposed properly #273

Open
piuccio opened this issue Jan 13, 2016 · 1 comment
Open

cleared mocks are not disposed properly #273

piuccio opened this issue Jan 13, 2016 · 1 comment

Comments

@piuccio
Copy link

piuccio commented Jan 13, 2016

Hi

I'm having an issue with requests completed after cleaning mocks

$.mockjax({
   url: '/hello',
   responseTime: 10000,
   responseText: "whatever"
});
$.get('/hello', function () {
   console.log('I don't expect to get here');
});
$.mockjax.clear();

The request is already in progress when I clear mockjax, but all clear does is prevent other request from starting. The ones already in progress cannot be stopped.

Do you have any suggestions?

Best would be implement #184 and handle this case in the clear or dispose. A quicker approach would be to keep track of pending requests.
I can't do it from my code because .response is called after responseTime and there's no event onBeforeRequest or beforeSend.

$.mockjax.mockedAjaxCalls() gets close to my need, but it only contains a list of requests, there's no reference to mockRequest = _ajax.call(). I could do with a $.mockjax.mockedAjaxRequests() but this method is not available.

@jakerella
Copy link
Owner

Hmm... This is tricky, the issue is that the setTimeout call is only used when responseTime is provided, otherwise we just call the underlying (original) $.ajax() method and it takes however long it takes. As such, implementing a beforeResponse event would not be consistent. Similarly, we can check to see if the mock is still valid after the setTimeout call expires, but it will not be consistent as we cannot do that for calls directly to $.ajax().

I'm open to ideas, but implementing #184 won't do this, even if you implemented a clear on that returned object because it could not be consistently applied. I'm open to options, but I don't see a clear winner yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants