From SG JS meetup with Tim Oxley. Spying on the number of times a function is called