ESC
Type to search...
S
Soli Docs

Testing Functions

Test DSL with describe/it blocks, assertions, and factory functions.

Test DSL

describe(description, fn)

Define a test group. context is an alias.

test(description, fn)

Define an individual test case.

it(description, fn)

Alternative to test(). specify is an alias.

Example

describe("Calculator", fn() {
    test("adds numbers", fn() {
        assert_eq(add(1, 2), 3)
    })

    it("subtracts numbers", fn() {
        assert_eq(subtract(5, 3), 2)
    })

    describe("division", fn() {
        it("divides numbers", fn() {
            assert_eq(divide(10, 2), 5)
        })

        it("handles division by zero", fn() {
            // Test error handling
        })
    })
})

Setup & Teardown

before_each(fn)

Run before each test

after_each(fn)

Run after each test

before_all(fn)

Run once before all tests

after_all(fn)

Run once after all tests

pending()

Mark test as pending (not yet implemented)

skip()

Skip the current test

Assertions

Basic Assertions

assert(condition)

Assert condition is true

assert_not(condition)

Assert condition is false

assert_eq(a, b)

Assert a equals b

assert_ne(a, b)

Assert a does not equal b

Null & Comparison

assert_null(value)

Assert value is null

assert_not_null(value)

Assert value is not null

assert_gt(a, b)

Assert a > b

assert_lt(a, b)

Assert a < b

Advanced Assertions

assert_match(str, pattern)

Assert string matches regex

assert_contains(coll, val)

Assert collection contains value

assert_hash_has_key(h, k)

Assert hash has key

assert_json(string)

Assert string is valid JSON

Factory Functions

Factory.define(name, data)

Define a factory with default data.

Factory.define("user", {
    "name": "Test User",
    "email": "[email protected]",
    "age": 25
})
Factory.create(name)

Create an instance from a factory.

let user = Factory.create("user")
println(user["name"])  // "Test User"
Factory.create_with(name, overrides)

Create an instance with custom overrides.

let admin = Factory.create_with("user", { "role": "admin" })
println(admin["role"])  // "admin"
println(admin["name"])  // "Test User" (from factory)
Factory.create_list(name, count)

Create multiple instances

Factory.sequence(name)

Get auto-incrementing number

Factory.clear()

Clear all factories