server.createList() and server.create() creates duplicate values with dynamic factory definition
See original GitHub issueIn my server I defined a factory
factories: {
story: Factory.extend<UserStory>({
get userStory() {
return faker.name.jobDescriptor();
},
get name() {
return faker.name.title();
},
get link() {
return faker.internet.url();
},
get status(): StoryStatus {
const num = getRandomInt(1, 4) as 1 | 2 | 3; //ranom
if (num === 1) {
return "Construction";
} else if (num === 2) {
return "Design";
} else {
return "Release";
}
},
get proxy() {
return faker.name.firstName();
},
}),
},
But when I call createList in my seeds function I am just getting a duplicate object for each of the 20 values
seeds(server) {
server.createList("story", 20);
}
I even tried just doing
seeds(server) {
server.create("story");
server.create("story");
server.create("story");
}
and each server.create() give me the same value.
I want it so I am give a unique object with different properties for each value, but it doesnt seem to be working.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Issues · miragejs/discuss - GitHub
createList() and server.create() creates duplicate values with dynamic factory definition. #57 opened on Dec 21, 2020 by tomcorey26.
Read more >Factories - Mirage JS
Factories are classes that help you organize your data-creation logic, making it easier to define different server states during development or within tests ......
Read more >Mirage JS Deep Dive: Understanding Factories, Fixtures And ...
Let's create records of the product model to be stored in Mirage database using the seeds method on our Server instance:.
Read more >Mocking Back-ends for React Apps with MirageJS
I keep the main server.ts file (where my Mirage server instance ... product data in the mock back-end, and they feature code duplication....
Read more >Issue with duplicate values generated when using factory_boy ...
The barcode is also the same between the two when calling create() on the factory. Do I need to provide a different seed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s a REPL that shows it: https://miragejs.com/repl/v2/3d7683e08a It uses the ‘getter’ concept in extending the factory as described above and also showcased in the miragejs typescript example: https://github.com/miragejs/examples/blob/master/react-typescript/src/mirage/index.ts
Based on the published typescript example my expectation would be that the getters defined in the factory would be called over and over, but they are only called once.
FYI - removing the ‘get’ from the property definitions does work as desired: https://miragejs.com/repl/v2/a1982958aa
I got duplicate entries in another scenario too. https://miragejs.com/repl/v2/bcc8e81470
Can you please tell me if my scenario is related to this issue?