Skip to content

Commit c7d7827

Browse files
committed
add description for dynamic fields
1 parent f0584ee commit c7d7827

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const book0 = await BookFactory.build();
9292
expect(book0).toStrictEqual({
9393
__typename: 'Book',
9494
id: 'Book-0',
95-
title: 'apple',
95+
title: expect.any(String),
9696
author: undefined,
9797
});
9898
assertType<{
@@ -109,11 +109,11 @@ const book1 = await BookFactory.build({
109109
expect(book1).toStrictEqual({
110110
__typename: 'Book',
111111
id: 'Book-1',
112-
title: 'orange',
112+
title: expect.any(String),
113113
author: {
114114
__typename: 'Author',
115115
id: 'Author-0',
116-
name: 'Tom',
116+
name: expect.any(String),
117117
books: undefined,
118118
},
119119
});
@@ -134,6 +134,24 @@ assertType<{
134134

135135
The library has several notable features. And many of them are inspired by [FactoryBot](https://thoughtbot.github.io/factory_bot/).
136136

137+
### Dynamic Fields
138+
139+
The `dynamic` function allows you to define fields with a dynamic value.
140+
141+
```ts
142+
import { dynamic } from '../__generated__/fabbrica';
143+
const BookFactory = defineBookFactory({
144+
defaultFields: {
145+
id: dynamic(() => faker.datatype.uuid()),
146+
title: 'Yuyushiki',
147+
},
148+
});
149+
expect(await BookFactory.build()).toStrictEqual({
150+
id: expect.any(String), // Randomly generated UUID
151+
title: 'Yuyushiki',
152+
});
153+
```
154+
137155
### Sequences
138156

139157
Sequences allow you to build sequentially numbered data.

0 commit comments

Comments
 (0)