-
Notifications
You must be signed in to change notification settings - Fork 0
mockTables
mockTables mocks Foundry’s RollTable class so that you can test code that uses it.
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: {}
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.
The name of the roll table you’d like the mock to return.
Default: 'Mock RollTable'
The total for the roll property that you’d like the mock to return when you call .draw.
Default: 1
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]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)
})
})