Testing unpublished add-on

Installable triggers and unpublished add-ons

As described in Setting up onChange trigger and When test add-ons doesn’t work you can’t install a trigger in test mode. The solution is to use your add-on as a library to a container bound script till you’re finished testing, then remove those links when ready to publish.


Like this

Setting up container bound script for testing

Once you’ve created a sheet and a script to go with it, you’ll need this code in it.

function onOpen(e) {

  SpreadsheetApp.getUi()
      .createMenu("testing addons")
      .addItem('Sheets efx demo', 'showViz')
      .addToUi();
      
}
function showViz () {

  var ui = SheetEfxDemo.libGetUi();
  SpreadsheetApp.getUi().showSidebar(ui);
}

// this is needed here as it will be called by the addon
/**
* used to expose memebers of a namespace
* @param {string} namespace name
* @param {method} method name
*/
function exposeRun(namespace, method, argArray) {
  
  var global = this;
  var func = namespace ? global[namespace][method] : global[method];

  if (argArray && argArray.length) {
    return func.apply(this, argArray);
  } else {
    return func();
  }
}
//expose library stuff that'll be accessed by the addon
var Server = SheetEfxDemo.Server;
var efxChanger = SheetEfxDemo.efxChanger;

Here the add-on is called SheetEfxDemo and it is included it as a library to the container bound script. The exposeRun function enables  calling namespaces from google.script.run and the other stuff is adding a menu item to call the add-on, so it now looks like this

For more like this, see Google Apps Scripts snippets

Find out more about Pushing Changes from Google Sheets server to client here