DirkScripts Logo

Login With FiveM

Login

📚 Library
â€ē
Modules
â€ē

test

Test

â„šī¸ Server & Client — write tests anywhere with lib.test.add, then run them from the server console with dirktest. It is console-only: a connected player can never trigger a test run.

lib.test is a lightweight, Jest-style test runner. It's ideal for validating bridges (inventory / framework / â€Ļ) and any server logic with a single console command — including bridge-compat suites that stay green across ox / qb / qs / devix / bp / etc.

lib.test.add

Register a test. The callback runs inside a coroutine, so it can lib.callback.await(...), call lib.inventory / lib.player, and Wait() freely.

lua
lib.test.add(name, fn, opts)
ParameterTypeRequiredDescription
namestringtrueTest name (also what the console filter matches)
fnfunctiontruefunction(ctx) ... end — receives the test context
optstablefalse{ requiresPlayer, context, skip } (see below)

opts

KeyTypeDescription
requiresPlayerbooleanPasses a connected player src as ctx.player; the test is skipped if no player is online
contextstring'server', 'client' or 'shared' (default) — the test only runs in a matching context
skipbooleanReported as skipped

The test context (ctx)

FieldDescription
ctx.expect(v)Chainable matchers (below); each throws on failure
ctx.playerTarget player src (server + requiresPlayer) or the local server id (client)
ctx.fail(msg)Force-fail with a message

Matchers

lua
ctx.expect(x).toBe(y)               -- equality (==)
ctx.expect(x).toEqual(y)            -- deep equality (tables)
ctx.expect(x).toBeTruthy()
ctx.expect(x).toBeFalsy()
ctx.expect(x).toBeNil()
ctx.expect(x).notToBeNil()
ctx.expect(x).toBeType('table')
ctx.expect(x).toBeGreaterThan(n)
ctx.expect(x).toBeGreaterOrEqual(n)
ctx.expect(x).toContain(v)          -- table contains value

Running tests

From the server console only:

dirktest                 -- run everything
dirktest inventory       -- only tests whose name contains "inventory"
dirktest xp 2            -- "xp" tests against player id 2
dirktest * 2 +c          -- everything on player 2, incl. client-side tests

Arguments are [nameFilter] [playerId] [+c] in any order.

âš ī¸ dirktest is console-only (guarded by source == 0) and registered as a restricted command — a player cannot run it whatever their permissions. requiresPlayer tests briefly mutate a player's inventory/data and restore afterwards, so run them on a test server, not a live one.

Example

lua
lib.test.add('inventory: add + remove roundtrip', function(t)
  local src = t.player
  local before = tonumber(lib.inventory.hasItem(src, 'water')) or 0

  lib.inventory.addItem(src, 'water', 2)
  Wait(200)
  t.expect((tonumber(lib.inventory.hasItem(src, 'water')) or 0) - before).toBe(2)

  lib.inventory.removeItem(src, 'water', 2)
end, { requiresPlayer = true })

Enabling it in your resource

The runner activates once lib.test is loaded. To guarantee it's available on both server and client (the client half powers the +c leg), declare it in your fxmanifest.lua:

lua
dirk_lib 'test'

server_script 'tests/server.lua'
client_script 'tests/client.lua'

â„šī¸ Cross-context note: lib.test lazy-loads per context, so the server command and the client endpoint only register when lib.test is touched in each context. The dirk_lib 'test' manifest flag force-loads it in both — which is why it's the recommended setup rather than relying on a lazy touch.

Copyright Š 2026 DirkScripts.

Not affiliated with or endorsed by Rockstar North, Take-Two Interactive, or any other rights holders. FiveM is a copyright and registered trademark of Take-Two Interactive Software, Inc.
Our checkout system is provided by Tebex Limited, who manage payment processing, product delivery, and billing support. Prices shown in currencies other than GBP are approximate conversions updated daily. All purchases are processed in GBP, so the final amount charged may vary depending on your bank or payment provider’s exchange rate.