Mock Google App Script's objects. Make developing and testing GAS simple.
npm install --save-dev app-script-mock
And before all your tests (you can use mocha's before
)
const extendGlobal = require('app-script-mock');
describe('[...]', () => {
before(() => {
extendGlobal(global);
});
});
This project emerged from another personal project that runs in Google App Script (QuickDrive). With the porpouse of getting your GAS project out of the cloud IDE that Google provides, app-script-mock offers a way to unit test your project.
You want to create a GAS that will read data from a Spreadsheet and then create a Form with questions based on data.
const functionThatCreatesFormsBasedOnSpreadsheet = () => {
//Your code here that uses FormApp/DriveApp/SpreadsheetApp
return form.getId();
}
describe('Should create a form with 3 questions based on spreadsheet', () => {
const createdFormId = functionThatCreatesFormsBasedOnSpreadsheet();
assert.equal(3, FormApp.openById(createdFormId).getItems().length);
})