Use spies instead of custom code.