testdouble.js vs. sinon.js by Justin Searls
https://getpocket.com/redirect?url=http%3A%2F%2Fblog.testdouble.com%2Fposts%2F2016-03-13-testdouble-vs-sinon.html
Creating a test double
In testdouble
stub
, spy
, mock
are created with the same syntax: td.function()
If it’s an object:
var dog = td.object(Dog)
dog.woof // a test double function
dog.bark // a test double function
of dog
has any property which is a function it will be replaced by a test double function.Replacing single properties
testdouble:
td.replace(process, ‘cwd’)
process.cwd
is now a test double functionNode.js module replacement
no longer need for sandboxed module :
var brake = td.replace(‘../../lib/brake’)
Depending on what it exports testdouble will replace the function (
td.function(‘brake’)
or the object (td.object()
)Stubbing responses
td.when(ask(‘meaning’)).thenReturn(42)
(ask is a test double function). Verify
td.verify(save(‘Joe’))
Rationale
Sinon provides a redundant way to create test doubles (mocks, stubs, spies) so most users don’t exactly know why they chose one over the other.
Testdouble simplifies and thus clarifies this.