Open KidkArolis opened 11 years ago
Your stubs, mocks, spies, etc. are automatically restored after each test. You only need to do it manually if you are using sinonjs in frameworks like QUnit (without the sinon-qunit integration).
I agree that the documentation is not clear. When I first started using buster, I followed the:
if(foo.bar.restore) foo.bar.restore();
template from the docs. But I eventually stopped doing it / removed it since it wasn't necessary. Since then, I've written a fair amount of tests:
32 test cases, 250 tests, 891 assertions, 1 failure, 0 errors, 0 timeouts
And I have not once have a problem with the tear down not working properly in all these tests. (The one failure is for a test I am in the middle of writing).
As you can see in this code, the tear down is automatic: https://github.com/busterjs/buster-sinon/blob/master/lib/buster-sinon.js
runner.on("test:tearDown", function (test) {
try {
test.testCase.sandbox.verifyAndRestore();
} catch (e) {
runner.assertionFailure(e);
}
});
sinon.expectation.pass = function () {
runner.assertionPass();
};
});
That's the behaviour I'm experiencing, but I can't find anything about it in the docs other than this example http://docs.busterjs.org/en/latest/modules/buster-test/test-case/#setup-and-teardown, where
jQuery.ajax.restore
existance is checked for. If buster automatically restores, then tearDown is not needed in this case? Or is there a case where it wouldn't be restored and so manually doing it is neccessary?