question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

server.createList() and server.create() creates duplicate values with dynamic factory definition

See original GitHub issue

In 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);
    }

Screen Shot 2020-12-21 at 3 28 54 PM

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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bkdextercommented, Mar 9, 2021

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

0reactions
mansur-gabidullincommented, Apr 12, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found