-
Notifications
You must be signed in to change notification settings - Fork 16
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
Sandbox object not accessible on context #57
Comments
Hmm... Look at Tell me if it works. (They roped me into being a contributor after I submitted a PR for something --- but I'm still still not quite at home with the coding style of the internals.... :)) A minimal enhancement might be to add (and document) an "extraSandboxProperties" option that would list any additional properties you wanted to add, without having to copy the list of default properties. |
I'll have a go, cheers! |
[The alternative enhancement would be just to add "reset" to the list of default properties. @fatso83 ?] |
I played around with this a bit and found that adding 'reset' is not sufficient, but I also found that you can expose the sandbox object by adding 'sandbox' to the list of properties. Unfortunately, this seems to have exposed a bug, where calling |
Fixed the bug causing a crash in sinonjs/sinon#1428. Back to the actual issue here, specifying var sinon = require('sinon');
var sinonTest = require('sinon-test');
sinon.test = sinonTest.configureTest(sinon, {
properties: ["stub", 'sandbox'] ,
useFakeServer: false // workaround for sinon#1428
});
var obj = { 'foo' : () => 'foo-val' }
console.log('before stub', obj.foo());
var testSuite = {}
testSuite.myTest = sinon.test( function() {
var stub = this.stub(obj, 'foo').callsFake( () => 'fake-val' );
console.log(obj.foo());
console.log('callCount:',stub.callCount, stub.called); // => 1
this.sandbox.reset();
console.log('callCount:',stub.callCount); // => 0
});
testSuite.myTest(); |
Brilliant, thank you! |
It would be nice to be able to access the sandbox object from the context object - particularly it would be useful to call
.reset()
on the sandbox for repeated tests.The text was updated successfully, but these errors were encountered: