/gs-kava

Lightweight framework for testing Google Apps Script.

Primary LanguageJavaScript

Kava

Lightweight framework for testing Google Apps Script.

Installation

Use file Kava.js in dist folder in your project. You can upload it, or simple copy & paste code to your GAS project.

Usage

At the new file write function with tests.

my.test.gs

function doTests() {
  const t = new Kava('Simple test');
  
  t.make('Should work', function() {
    t.isEqual('abc', 'abc');
  });

  t.make('Should throw', function() {
    t.isEqual('abc', 'cde');
  });
  
  Logger.log(t.output);
}

Running function doTests() will generate output:

Simple test:
----
1. Should work - OK
----
2. Should throw - ERROR
> Error: expected cde, but received abc
----
* Total: 2, errors:1

API

Kava

For testing purpose in Google Apps Script projects

Kind: global class

kava.errCount

Return count of errors

Kind: instance property of Kava

kava.output

Getter make formatted text output of test results. Start it at finish tests

Kind: instance property of Kava

kava.moduleName(name)

Set module name that testing

Kind: instance method of Kava

Param Type Description
name String module name

kava.compareWith(reference) ⇒ function

Check, if all keys and values from sample has comparing object. Throw exception, if is not equal.

Kind: instance method of Kava
Returns: function - that take as argument object for comparing

Param Type Description
reference Object Key-value object that used for sample for comparing

Example

const kava = new Kava('Description');
const assertion = { a: 1, b: 2 };
const compare = kava.compareWith(assertion);
compare({ a: 1, b: 2}); // OK
compate({ a: 1, c: 3 }); // Throw exception

kava.isEqualByKey(key, received, expected)

Comparing values by same key in the two objects. Throw exception, if is not equal.

Kind: instance method of Kava

Param Type Description
key String Key by which the value will be checked
received Object Object, which compared
expected Object Object, used as reference

kava.isEqual(received, expected)

Compare two primitive type values. Throw exception, if is not equal.

Kind: instance method of Kava

Param Type Description
received * value, that compared
expected * sample value