The name comes from a famous spy,
but it also fits gramatically.
bonding a reference
to a value:
You can checkout the full README for a breakdown of the api, but I wanted to call out the core concepts here.
The core method accepts an
returning the bond api.
The bond api allows you to stub or spy on this property.
For example, you could stub a method to return a specific value with
You can also stub a value property with
There are some cases where you want to spy on a method without changing it.
For that, you can use
When you create a bond spy,
you can check to see how many times it was called with
I abuse the fact that 0 is falsey when I use this method:
if spy.called then ....
You can check that a spy was called with specific arguments as well:
spy.calledWith(arg1, arg2, ...).
I have been using bond for about a year now. I find that it does exactly what I need.
You can even use it to write a quick
for those cases where a module only exports a function
and you can’t stub or spy on it.
stubModule = (modulePath, stub) -> resolvedPath = require.resolve(modulePath) require.cache[resolvedPath] = stub
Let me know how you like bond below!