Write IML tests
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}`;
}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);
});Common asserts functions
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.

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

Last updated

