matheusmr13 / app-script-mock

Mock Google App Script's objects. Make developing and testing GAS simple.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

app-script-mock

Mock Google App Script's objects. Make developing and testing GAS simple.

Coverage Status Coverage Status Coverage Status

Install

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);
	});
});

Why?

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.

Example

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);
})

About

Mock Google App Script's objects. Make developing and testing GAS simple.

License:Apache License 2.0


Languages

Language:JavaScript 100.0%