tiny-fixtures / Exports
tiny-fixtures
Table of contents
Type aliases
- CreateFixtures
- ResultArray
- RowHelpers
- SetupFixtures
- TeardownFixtures
- TinyFixtures
- TinyFixturesOptions
Functions
Type aliases
CreateFixtures
Ƭ CreateFixtures: <T>(table
: string, rows
: T[], primaryKeyName?
: string) => [SetupFixtures, TeardownFixtures, ResultArray<T>]
Use this function to create a set of fixtures for a particular table in the database.
param
The name of the table to insert test data into.
param
An array of objects containing test data. Each object is a row where keys are column names.
param
Optional name of the primary key column. If not provided, it is assumed that the first column is the primary key. Tiny-fixtures does not support composite primary keys.
returns
- An array containing setup and teardown functions, plus ResultArray
Type declaration
▸ <T>(table
: string, rows
: T[], primaryKeyName?
: string): [SetupFixtures, TeardownFixtures, ResultArray<T>]
Type parameters
Name | Type | Description |
---|---|---|
T |
object | The type of the objects representing each row. |
Parameters
Name | Type |
---|---|
table |
string |
rows |
T[] |
primaryKeyName? |
string |
Returns: [SetupFixtures, TeardownFixtures, ResultArray<T>]
Defined in: index.ts:54
ResultArray
Ƭ ResultArray<T>: T & RowHelpers[]
This array contents changes depending whether tests are being prepared or running
## Preparation
At this point the data in this array is simply the data you passed to createFixtures
, extended with RowHelpers
. Since the inserts only occur in the before
or beforeEach
step, it is impossible to have the result of the insert before it has occurred.
## Running tests
Inside your it
statement, after the before
or beforeEach
step has occurred, this array is now populated with the data returned by the database. So any SERIAL
or DEFAULT
columns will be accessible here.
Type parameters
Name |
---|
T |
Defined in: index.ts:43
RowHelpers
Ƭ RowHelpers: object
When the createFixtures function returns an array of the rows you’ve chosen to insert with test data, they are extended with these row helpers.
Type declaration
Name | Type | Description |
---|---|---|
getRefByKey |
(key : string) => () => string | number |
Using this function tells tiny-fixtures to get a value from this fixture after it has been inserted in the database, rather than the test data provided by you. This is useful for cases such as accessing a primary key to create a join, or retrieving a default value, such as the result of DEFAULT NOW() You only need to use this function to tell tiny-fixtures to retrieve this column at insert. When your tests are running, they will have access to the resulting insert if needed, as tiny-fixtures updates the row array on the fly. param The name of the column to retrieve. returns A function that can be executed later to retrieve the value |
Defined in: index.ts:21
SetupFixtures
Ƭ SetupFixtures: () => Promise<any[]>
Call this function inside your before
or beforeEach
step to insert the specified fixtures
Type declaration
▸ (): Promise<any[]>
Returns: Promise<any[]>
Defined in: index.ts:11
TeardownFixtures
Ƭ TeardownFixtures: () => Promise<void>
Call this function inside your after
or afterEach
step to delete the specified fixtures. This will only delete the data inserted for this fixture, so any other test data remains untouched.
Type declaration
▸ (): Promise<void>
Returns: Promise<void>
Defined in: index.ts:16
TinyFixtures
Ƭ TinyFixtures: object
Contains the createFixtures function, with the pool in its closure.
Type declaration
Name | Type |
---|---|
createFixtures |
CreateFixtures |
Defined in: index.ts:63
TinyFixturesOptions
Ƭ TinyFixturesOptions: object
Type declaration
Name | Type |
---|---|
convertToSnakecase |
boolean |
Defined in: index.ts:73
Functions
tinyFixtures
▸ Const
tinyFixtures(pool
: Pool, __namedParameters?
: TinyFixturesOptions): TinyFixtures
Parameters
Name | Type | Description |
---|---|---|
pool |
Pool | A node postgres pool for tiny fixtures to connect with. |
__namedParameters |
TinyFixturesOptions | - |
Returns: TinyFixtures
Defined in: index.ts:85