Specifying Test Double Behavior
Learn how to specify and add the behavior for test doubles. Learn test double instance methods, and how to use them with multiple matchers.
We'll cover the following...
Once we have a testdouble.js
function, we need to specify some behavior, analogous to how RSpec’s test doubles use allow
and expect
with chained methods like to_receive
.
Adding behavior
In testdouble.js
, we add behavior with the when
method, and the API to it is a little unusual. Here’s a basic usage:
const fake = td.object["remoteInit"]
td.when(fake.remoteInit(1)).thenReturn(7)
There are two parts to this when
invocation:
- The call to
when
itself. - The chained method afterward that defines the behavior.
The argument to when
is meant to be the entire ...