3

Is there a recommended way to stub out the gapi.client api? I'd like to test its integration with some of my applications' functionality, and think I have to constantly manually stub out responses.

Is there an existing stubbing library out there?

btelles
  • 5,390
  • 7
  • 46
  • 78

1 Answers1

2

There are projects that include stubs for specific methods, but there is no plug-and-play library that covers the complete API (as far as I know). Maybe you could use some of the test code Google published on the official Google Analytics repository on GitHub.

That said, gapi.client is an easy target for mocking and your safest bet migt be to do it yourself.

As a side note: Sinon.JS might be very helpful to speed up that process. It eases replacing functions, returning sample data, and more. Sinon makes it easy to "spy" on the methods that would usually result from trying to connect to the remote server, and these spies can easily be plugged into suitable assertions. No dependencies, works with any unit testing framework.

Good luck!

pesla
  • 1,244
  • 8
  • 8