user1930364
user1930364

Reputation: 49

Mocking Google Earth events with require.js and jasmine

I have the following module, but I am having difficulty in setting this up for mocking during my jasmine tests (ie - inside of my test harness). In particular, I was wondering how I would/should go about substituting the async!https://www.google.com/jsapi call (or hard-coded url reference) within the context of the test harness, and also which events I would spyOn inside of the tests for both "google.load" and "google.earth.createInstance" in order to trigger the callbacks properly within my tests? In the sample code below, the uiSelector argument would be the div id into which the earth map is loaded.

Thanks in advance for your time.

define('googleearthloader',
[ "async!https://www.google.com/jsapi" ],
function() {

return {
        init: function(uiSelector, callbackSuccess,callbackError) {
            google.load("earth", "1", { 'callback': function() { google.earth.createInstance(uiSelector, callbackSuccess, callbackError); } });
            }

       };

});

Upvotes: 0

Views: 268

Answers (1)

skusunam
skusunam

Reputation: 411

You can just do this:

var spy = sinon.stub(google, 'load');
.....your init call
expect(spy).toHaveBeenCalledWith("earth1", "1");

You can test what ever you want with this spy stub call.

Upvotes: 1

Related Questions