Skip to content
Testing library for Google Apps Script
Branch: master
Clone or download
dependabot and munierujp Bump js-yaml from 3.12.0 to 3.13.1 (#25)
Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 3.12.0 to 3.13.1.
- [Release notes](https://github.com/nodeca/js-yaml/releases)
- [Changelog](https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md)
- [Commits](nodeca/js-yaml@3.12.0...3.13.1)

Signed-off-by: dependabot[bot] <support@github.com>
Latest commit 00bea82 Jul 20, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.doc Update docs (#21) Jun 13, 2019
src To TypeScript (#23) Jun 27, 2019
test To TypeScript (#23) Jun 27, 2019
.clasp.json Apply clasp (#14) Sep 18, 2018
.eslintrc.json To TypeScript (#23) Jun 27, 2019
.gitignore Apply clasp (#14) Sep 18, 2018
README.md Update README.md Jun 17, 2019
package-lock.json Bump js-yaml from 3.12.0 to 3.13.1 (#25) Jul 20, 2019
package.json Fix start command (#24) Jun 30, 2019
tsconfig.json To TypeScript (#23) Jun 27, 2019

README.md

clasp JavaScript Style Guide

GASUnit

banner

Testing library for Google Apps Script. Result will be logged to Logger, or posted to Slack.

Usage

Add library

project key: MSnMmw8hLWgjUG6uKSTQBEzVZgzu5bsVr

Write tests

You can use Exports style to write tests (for now).

Exports style

Exports style is inspired by Mocha.

Use Logger:

var exports = GASUnit.exports
var assert = GASUnit.assert

function test_array () {
  exports({
    'Array': {
      '#indexOf()': {
        'should return -1 when not present': function () {
          assert([1, 2, 3].indexOf(4) === -1)
        },
        'should return the index when present': function () {
          assert([1, 2, 3].indexOf(3) === 3)
        }
      }
    }
  })
}

Use Slack:

var WEBHOOK_URL = 'https://...'
var exports = GASUnit.slack(WEBHOOK_URL).exports
var assert = GASUnit.assert

function test_array () {
  exports({
    'Array': {
      '#indexOf()': {
        'should return -1 when not present': function () {
          assert([1, 2, 3].indexOf(4) === -1)
        },
        'should return the index when present': function () {
          assert([1, 2, 3].indexOf(3) === 3)
        }
      }
    }
  })
}

If you're publishing source code, should not write webhook url as a literal. You can use properties as environment variables.

var WEBHOOK_URL = PropertiesService.getScriptProperties().getProperty('WEBHOOK_URL')
var exports = GASUnit.slack(WEBHOOK_URL).exports
var assert = GASUnit.assert

function test_array () {
  exports({
    'Array': {
      '#indexOf()': {
        'should return -1 when not present': function () {
          assert([1, 2, 3].indexOf(4) === -1)
        },
        'should return the index when present': function () {
          assert([1, 2, 3].indexOf(3) === 3)
        }
      }
    }
  })
}

Or you can...

var WEBHOOK_URL = PropertiesService.getScriptProperties().getProperty('WEBHOOK_URL')
var exports = WEBHOOK_URL ? GASUnit.slack(WEBHOOK_URL).exports : GASUnit.exports
var assert = GASUnit.assert

function test_array () {
  exports({
    'Array': {
      '#indexOf()': {
        'should return -1 when not present': function () {
          assert([1, 2, 3].indexOf(4) === -1)
        },
        'should return the index when present': function () {
          assert([1, 2, 3].indexOf(3) === 3)
        }
      }
    }
  })
}

Assertion

GASUnit provides minimum assert function which verify whether value is truthy. You can use any assertion library (for Google Apps Script). GASUnit also provides AssertGAS as official assertion library.

Development

See package.json

Example

See gasunit/example

Article

Japanese

You can’t perform that action at this time.