September 2018
Intermediate to advanced
764 pages
20h 6m
English
Stubs are functions that simulate the behavior of another component.
In the context of our tests, we don't really care about the returned value of res.json() – we only care that our checkEmptyPayload middleware function relays this value back faithfully. Therefore, we can turn our res.json spy into a stub, and make it return a reference to an object:
resJsonReturnValue = {};res = { status: spy(), set: spy(), json: stub().returns(resJsonReturnValue),};
We can then add another assertion step to compare the value returned by the checkEmptyPayload function, and the value returned by ...
Read now
Unlock full access