File tree Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Expand file tree Collapse file tree 1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -92,7 +92,7 @@ const book0 = await BookFactory.build();
92
92
expect (book0 ).toStrictEqual ({
93
93
__typename: ' Book' ,
94
94
id: ' Book-0' ,
95
- title: ' apple ' ,
95
+ title: expect . any ( String ) ,
96
96
author: undefined ,
97
97
});
98
98
assertType <{
@@ -109,11 +109,11 @@ const book1 = await BookFactory.build({
109
109
expect (book1 ).toStrictEqual ({
110
110
__typename: ' Book' ,
111
111
id: ' Book-1' ,
112
- title: ' orange ' ,
112
+ title: expect . any ( String ) ,
113
113
author: {
114
114
__typename: ' Author' ,
115
115
id: ' Author-0' ,
116
- name: ' Tom ' ,
116
+ name: expect . any ( String ) ,
117
117
books: undefined ,
118
118
},
119
119
});
@@ -134,6 +134,24 @@ assertType<{
134
134
135
135
The library has several notable features. And many of them are inspired by [ FactoryBot] ( https://thoughtbot.github.io/factory_bot/ ) .
136
136
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
+
137
155
### Sequences
138
156
139
157
Sequences allow you to build sequentially numbered data.
You can’t perform that action at this time.
0 commit comments