Write IML tests

When using IML functions that work with date and time, remember to set the correct timezone in extension settings. The accepted format is the international time zone format.

For example "Europe/Prague"

Write a test

It's possible to write tests for your custom IML functions. You can use the it function and asserts.

function formatUsername(user) {
    if (!user || !user.firstName || !user.lastName) {
        return null;
    }
    return `${user.firstName} ${user.lastName}`;
}

Common asserts functions

Function
Description

assert.ok(value)

Passes if value is truthy.

assert.strictEqual(actual, expected)

Passes if actual === expected.

assert.deepStrictEqual(actual, expected)

Passes if objects or arrays are deeply equal.

assert.notStrictEqual(actual, expected)

Passes if values are not strictly equal.

assert.throws(fn, [error])

Passes if the function throws an error.

assert.doesNotThrow(fn)

Passes if the function does not throw an error.

assert.match(string, regex)

Passes if the string matches the regex.

assert.doesNotMatch(string, regex)

Passes if the string does not match the regex.

Run a test

To run a test on a specific function, right-click the function name in the tree and select Run IML test.

Run IML test option

The test starts and the output is in the IML tests output channel.

Learning more about debugging your custom IML function in VS Code.

Last updated