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

Add Unique ID to all mock handlers? #184

Open
jakerella opened this issue Oct 2, 2014 · 8 comments
Open

Add Unique ID to all mock handlers? #184

jakerella opened this issue Oct 2, 2014 · 8 comments
Labels

Comments

@jakerella
Copy link
Owner

I'm wondering if we should assign a proper ID to each mock handler. Currently this is just the index in the array of handlers, but that seems fragile. Having proper IDs would still allow clearing individual requests or all handlers, but would eliminate the possibility of the calling code holding onto that index past when it should, then trying to use it and clearing a mock handler that it did not intend to.

Any thoughts @dcneiner or @jcreamer898 (or anyone else)?

@dcneiner
Copy link
Collaborator

dcneiner commented Oct 4, 2014

Possibly – but I wonder if a more traditional approach could be used. For instance, each mock would get a lightweight instance wrapper that is returned instead of a number when $.mockjax is called. Then we could have a destroy method. It also opens the possibility to have more functionality like disable and enable. This would allow someone to create a mock that they can disable and only enable when they need it, or vice versa. Not sure. Just an idea.

selfie-1

@jakerella
Copy link
Owner Author

Ooooooooh, yes. I like that idea. Returning a wrapper with a couple helper methods. Let me think on this and I'll suggest a format in here.

@jcreamer898
Copy link
Collaborator

What all could be included here?

var mock = $.mockjax({
   url: '/foo'
});

mock.id; // 12345
mock.options; // { /* ... */ }
mock.destroy(); 

@jakerella
Copy link
Owner Author

I would argue that we make it mostly functions versus properties, that way we can change implementations later. But what you have so far is a good start:

var mock = $.mockjax({ ... });
mock.getId();
mock.getSettings();
mock.clear(); // versus "destroy", this keeps it in line with $.mockjax.clear()
mock.callCount(); // we already have this info sorta... just have to access it

That's all i can think of right now.

@jakerella jakerella mentioned this issue Nov 7, 2014
8 tasks
@jakerella jakerella modified the milestone: 2.1.0 Apr 14, 2015
@piuccio
Copy link

piuccio commented Jan 13, 2016

returning a wrapper would be really handy 😁

@piuccio
Copy link

piuccio commented Jan 13, 2016

I realise my message was too concise, the wrapper should also include a mockedAjaxCalls() which returns the same thing as $.mockjax.mockedAjaxCalls() but filtered by that single mock.

@jakerella
Copy link
Owner Author

Great idea! I'm super busy on other things right now, but I'd like to implement this at some point. It needs to be done carefully, however, so that it doesn't break existing code (if possible).

@piuccio
Copy link

piuccio commented Jan 13, 2016

changing the return value of $. mockjax is not trivial. One backward compatible option would be to call

var wrap = $.wrapperFor($.mockjax(...));

a bit ugly 😁

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

No branches or pull requests

4 participants