Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make falso instantiable #347

Open
slioxo opened this issue Feb 1, 2023 · 1 comment
Open

Make falso instantiable #347

slioxo opened this issue Feb 1, 2023 · 1 comment

Comments

@slioxo
Copy link

slioxo commented Feb 1, 2023

Description

Picture this:

function createPerson() {
  seed('person-seed');
  return {
     name: randFullName(),
     company: createCompany(),
     job: randJobTitle()
  };
}

function createCompany() {
  seed('company-seed');
  return {
    name: randCompanyName(),
    city: randCity()
  };
}

In this example, randJobTitle() is called with company-seed instead of person-seed, because the createCompany() that's called before it has changed the seed globally.

Proposed solution

In such cases it would be great if we were able to instantiate falso, like so

function createPerson() {
  const falso = new Falso();
  falso.seed('person-seed');
  return {
     name: falso.randFullName(),
     company: createCompany(),
     job: falso.randJobTitle()
  };
}

function createCompany() {
  const falso = new Falso();
  falso.seed('company-seed');
  return {
    name: falso.randCompanyName(),
    city: falso.randCity()
  };
}

This would isolate and prevent unexpected side effects like in the example above, where changing the seed somewhere affects the whole application after it.

Alternatives considered

No response

Do you want to create a pull request?

No

@gerardolima
Copy link

gerardolima commented Jun 30, 2023

This is important for test runners that don't isolate the runner processes (ie. mocha, Node built-in test runner, ...). The implementation could as well be done creating an object factory, that would avoid prototype, while keeping TS interface guarantees.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants