Lightweight framework for testing Google Apps Script.
Use file Kava.js
in dist
folder in your project. You can upload it, or simple copy & paste code to your GAS project.
At the new file write function with tests.
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
For testing purpose in Google Apps Script projects
Kind: global class
Return count of errors
Kind: instance property of Kava
Getter make formatted text output of test results. Start it at finish tests
Kind: instance property of Kava
Set module name that testing
Kind: instance method of Kava
Param | Type | Description |
---|---|---|
name | String |
module name |
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
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 |
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 |