For the complete documentation index, see llms.txt. This page is also available as Markdown.

Write IML tests

You can write tests for your custom IML functions. Use the it function and asserts.

function formatUsername(user) {
    if (!user || !user.firstName || !user.lastName) {
        return null;
    }
    return `${user.firstName} ${user.lastName}`;
}
it("should format full name correctly", () => {
    const user = { firstName: "Jane", lastName: "Doe" };
    const result = formatUsername(user);
    assert.strictEqual(result, "Jane Doe");
});

it("should return null if last name missing", () => {
    const user = { firstName: "Jane" };
    const result = formatUsername(user);
    assert.strictEqual(result, null);
});

The it function accepts exactly two parameters, the name of the test and the code to run. In this code, we can verify expected outputs using assert.ok() function.

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"

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.

Last updated