Skip to content

mockTables

Jason Godesky edited this page Jul 18, 2026 · 1 revision

mockTables mocks Foundry’s RollTable class so that you can test code that uses it.

Parameters

tables: Record<string, Partial<{ uuid: string, name: string, roll: number, results: foundry.documents.TableResult[] }>>

Options concerning the roll tables you’d like to mock. The keys are UUIDs for each roll table.

Default: {}

tables[uuid].uuid

The UUID of the roll table you’d like the mock to return (a real roll table in Foundry will always begin with RollTable.).

Default: RollTable. concatenated with an ID generated using generateID.

tables[uuid].name

The name of the roll table you’d like the mock to return.

Default: 'Mock RollTable'

tables[uuid].roll: number

The total for the roll property that you’d like the mock to return when you call .draw.

Default: 1

tables[uuid].results: foundry.documents.TableResult[]

The results that you would like the mock to return when you call .draw. As full Foundry Documents, a full TableResult object would be impractical to write out. We recommend sticking to those elements that your code actually uses, as in the example below.

Default:

[{
  name: 'Mock RollTable Result #1',
  description: 'This is the first result in the mock RollTable.'
} as foundry.documents.TableResult]

Examples

import { beforeEach, afterEach, describe, expect, it, vi } from 'vitest'
import { mockTables } from '@revolutionarygamesco/common-foundryvtt/mocks'
import { drawName } from '@revolutionarygamesco/common-foundryvtt'

describe('drawName', () => {
  const uuid = 'RollTable.1111111111111111'
  const roll = 10
  const name = 'Name'
  const description = 'Description'

  beforeEach(() => {
    mockTables({
      [uuid]: { uuid, name, roll, results: [{ name, description } as foundry.documents.TableResult] }
    })
  })

  afterEach(() => {
    vi.unstubAllGlobals()
  })

  

  it('draws the name from the first table result', async () => {
    const actual = await drawName('table')
    expect(actual).toBe(name)
  })
})

Clone this wiki locally