-
Notifications
You must be signed in to change notification settings - Fork 12
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
Restore a specific mock/spy #9
Comments
Hey, sorry I missed this issue. In this particular example, the I usually try to keep shared setup for subsequent tests in something such as a |
So, correct me if I'm wrong: the problem is that currently the |
Correct. This behaviour enables you to chain behaviour instructions, e.g. simple.mock(object, 'key')
.returnWith('something')
.throwWith(new Error('already returned')` I do realise that the case for simple value substitution, i.e. not a method mock, does not benefit from chaining anyway. Would an API such as |
That method could work, but I'm worried about multiple mocks replacing the same value. My work so far: var str = "hi";
var strWithRestore = Object(str);
strWithRestore.restoreMock = function() {
return console.log("Hello!");
};
var testing = {
hi: "1",
hello: "2"
};
testing[str]; // Gives '1'
testing[strWithRestore]; // Still gives '1'
typeof strWithRestore == "string" // Doesn't work, returns 'object' |
That's perhaps a bit too clever, changing to a string object. I've implemented the |
Add granular mock restore to resolve #9
Awesome, thanks! My confusion about conflicting mocks was that I, for whatever silly reason, thought you meant to implement it like so: mockDir = simple.mock(object, "key", "new information")
do_something()
simple.restore(mockDir) Which would fail if |
Hello! First off, I love this tool. I took one look at sinon and instantly sought a more intuitive method, and I wound up finding this! I only have one request, which is a
restore()
function on individual mocks. In my tests I'm finding myself needing to mocks for one method call that need to be undone before the next one, and I would like a way to not have to redo all the other mocks and spies.Proposed format:
The text was updated successfully, but these errors were encountered: