Coder Social home page Coder Social logo

gas-mock-globals's Introduction

Gas Mock Globals

Build Status codecov npm version

This is a collection of Google Apps Script services polyfills which can be used to mock Apps Script globals in your tests.

Installation

npm install --save-dev gas-mock-globals

Usage

Add import statement to the top of your script to load polyfills into global scope:

import 'gas-mock-globals'   // es-modules
require('gas-mock-globals') // common-js

Or use exact class without global namespace pollution:

import CardService from 'gas-mock-globals/src/card/CardService'
import Utilities from 'gas-mock-globals/src/utilities/Utilities'

const cardSection = CardService.newCardSection();
// Finish building the card section ...

const header = CardService.newCardHeader().setTitle(Utilities.base64Encode('Card title'))

const card = CardService.newCardBuilder()
  .setName('Card name')
  .setHeader(header)
  .addSection(cardSection)
  .build();

And then you can use any JS testing framework to test your code intended to run on Apps Script environment:

// apps-script-code-module.js
function dummyFunction () {
  PropertiesService.getUserProperties().setProperty('DAYS_TO_FETCH', '5');
  Logger.log('Current user\'s email', Session.getActiveUser().getEmail())
  Logger.log('Encoded value', Utilities.base64Encode('john doe'))
  return 'i\'m dummy'
}

// test
test('dummy test', () => {
  expect(dummyFunction()).toEqual('i\'m dummy')
})

See more examples in examples directory.

Contribution

To contribute you should make sure that:

  • you've covered your code with tests
  • all the tests pass if you run npm test

Useful links

gas-mock-globals's People

Contributors

dan-kushnaryov avatar myokha avatar jsarafajr avatar maxidr avatar dupski avatar dkushnarov avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.