I\'ve created a database wrapper for my application, shown below. To test it, I obviously would like to replace the actual database library. I could create a new class that mock
You can use both for that.
Mock have an expected ordered behavior that, if not followed correctly, is going to give you an error.
A Stub is a similar to a mock, but without the order, so you can call your methods the way you want. In my experience you almost never need a mock.
Both of them will substitute your method for an empty method, or a closure if you pass one. It would be something like this:
stub = sinon.stub(wrapper , 'insertUser ', function () { return true; });
Then you add the expect behavior to check if it did happened.
I like to use Jasmine with Jasmine-Sinon for checking the tests.