Recording or mocking HTTP requests made by the Maps API is certainly an interesting idea!
Unfortunately, like any other undocumented API functions, these requests are an internal implementation detail and can be changed at any time. Google releases new versions of the API code four times a year, as well as patch fixes as often as every few weeks. Any of the internal API components, including HTTP requests, can change from one version to another, even in patch versions. The only thing that they guarantee a stable version or patches is a documented API.
Google gives you the opportunity to request a specific version of the API , but they do not support old versions for a very long time, and they do not keep the old patch fixes at all. In fact, only three versions are available at any time. With this writing of these versions are available:
- The experimental version, currently 3.21.4.
- Release version, currently 3.20.12.
- The frozen version, currently 3.19.19.
When the next experimental version (3.22) is released, 3.21 will become the release version, 3.20 will be the frozen version, and 3.19 will be deleted and will no longer be available.
The frozen version has one difference from the release and experimental versions: it no longer receives any patches, so it is completely stable. It is safe to assume that HTTP requests made by the frozen version will not change. But this helps only until this version is removed.
Here is a fiddle to experiment with requesting different versions of the API and displaying which version is actually loaded. The code is as follows:
<!DOCTYPE html> <html> <head> <title>Google Maps API version test</title> </head> <body> <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script> <script src="http://maps.google.com/maps/api/js?v=3.18&sensor=false"></script> <div id="version"></div> <script> $('#version').text( 'google.maps.version is ' + google.maps.version ); </script> </body> </html>
The violin uses the v=3.18 parameter in the Maps API script URL to request version 3.18, but currently it is loading version 3.19.19. You can change the v= parameter to different values ββto see which version of the API is loaded. (In addition to specific numbered versions, you can also use v=3 to get the current stable version or v=3.exp to get the current experimental version.)
A sharp-eyed reader may notice that the google.maps.version property displayed by this code is not documented itself! But hey, this is an experimental test code. :-)
This is a fairly common occurrence when HTTP requests change from version to version and can even be changed in a patch fix. As you can see from the list above, version 3.19 went through 19 fixes for patches, and 3.20 went through 12 fixes for patches.
If you want to write unit tests for your Maps API code, my suggestion is to mock the documented Maps API, rather than mock any of its internals. For example, your layout for google.maps.Map can verify that its first parameter is a DOM node and that its second (optional) parameter object contains only known properties with legal values ββfor these properties.
Of course, the Maps API provides a fairly large number of objects, methods and properties, but you do not need to scoff at all of this, only those parts that you use.