I'm writing some JavaScript module that is meant to running in browser (client side, not server side). This module is using Google Maps JavaScript API.
I want to cover my code by unit tests. I also want my tests to be isolated. I found several vcr-like JS libraries for recording and mocking HTTP-requests that Google Maps Api is producing. But all of them are for Node.JS (because PhantomJS doesn't support using fs
module). Also Node.JS has more rich and readable backtraces than PhantomJS has.
So I'm wondering how to include Google Maps Javascript API to my tests with Node.JS-based test runner and how to write test for my code?
P.S. I'm not stick with some certain JS unit-test library. It can be Jasmine, QUnit or any other.
P.P.S It not necessary should be Node.JS runner. If there are another options it is completely OK!
P.P.P.S. My goal is to avoid following things:
- to avoid dependency on internet connection and corresponding delays in tests
- to avoid failing tests because of changing some GEO data on Google servers. For example: if I use directions, I don't really care if it 2000 meters or 2001 meters, I just wanna know, that I get some appropriate data from Google and perform some calculations with it.
P.P.P.P.S. Thanks to @MichaelGeary answer we know that Google saves only 3 versions of their API. But I'm not focusing only on Google Maps, I chose it in that question because of it's popularity/ I have the same question applied to any other maps api like Yandex.Maps, Leaflet (with openstreet), Bing and etc. Most of them don't delete old APIs, so I can fix version and rely on not changing internal API and HTTP requests.
Also I want to avoid mock hell, because my code is quite complex and uses a lot of geo objects of different kind. So it will not be easy to mock all of them and then support that code. It looks like unbearable thing.
My idea is to fix version of API for some time (in Google case for not so long time) and rely on persistence of internal HTTP requests format. And from time to time delete all recorded data to be sure that everything is still OK in real world.
I want myself to be one who control when I should fix my test. I don't wanna Google to break my tests at random moment of time.