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

[Module 2] - Faker does not exists #22

Open
KeevenOliveira opened this issue Aug 13, 2022 · 1 comment
Open

[Module 2] - Faker does not exists #22

KeevenOliveira opened this issue Aug 13, 2022 · 1 comment

Comments

@KeevenOliveira
Copy link

English

Hello guys, I'm studying the module 2 and I found one problem in faker library. This problem is caused because the 'Faker' library does not exists anymore.

I recommend that you use this library: @faker-js/faker

Click here to know more about this library

You can install with yarn and npm:

yarn add @faker-js/faker --dev
npm install @faker-js/faker --save-dev

Code recommendation

In miragejs/factories/message.js, you can use this code:

import { Factory } from 'miragejs';

import { faker } from '@faker-js/faker';

export default {
  message: Factory.extend({
    content() {
      return faker.name.fullName();
    },
    date() {
      const date = new Date(faker.date.past());
      return date.toLocaleDateString();
    },
  }),
};

And in miragejs/factories/user.js, you can use this code:

import { randomNumber } from './utils';

import { Factory } from 'miragejs';

import { faker } from '@faker-js/faker';

export default {
  user: Factory.extend({
    name() {
      return faker.name.fullName();
    },
    mobile() {
      return faker.unique(faker.datatype.uuid);
    },
    afterCreate(user, server) {
      const messages = server.createList('message', randomNumber(10), { user });

      user.update({ messages });
    },
  }),
};

Have a good code study!👊👨‍💻👩‍💻

Português

Olá pessoal, estou estudando o módulo 2 e encontrei um problema na biblioteca faker. Este problema é causado porque a biblioteca 'Faker' não existe mais.

Eu recomendo que você use esta biblioteca: @faker-js/faker

Clique aqui para saber mais sobre esta biblioteca

Você pode instalar com yarn e npm:

yarn add @faker-js/faker --dev
npm install @faker-js/faker --save-dev

Recomendação de código

No miragejs/factories/message.js, você pode usar este código:

import { Factory } from 'miragejs';

import { faker } from '@faker-js/faker';

export default {
  message: Factory.extend({
    content() {
      return faker.name.fullName();
    },
    date() {
      const date = new Date(faker.date.past());
      return date.toLocaleDateString();
    },
  }),
};

E no miragejs/factories/user.js, você pode usar este código:

import { randomNumber } from './utils';

import { Factory } from 'miragejs';

import { faker } from '@faker-js/faker';

export default {
  user: Factory.extend({
    name() {
      return faker.name.fullName();
    },
    mobile() {
      return faker.unique(faker.datatype.uuid);
    },
    afterCreate(user, server) {
      const messages = server.createList('message', randomNumber(10), { user });

      user.update({ messages });
    },
  }),
};

Tenha um ótimo estudo de código!!👊👨‍💻👩‍💻

@stamorim28
Copy link

Para evitar alertas no console de quem instalou o faker-js acima da versão 7.5 deve adicionar o helpers antes do unique no método mobile do arquivo user.js.

mobile() {
   return faker.helpers.unique(faker.datatype.uuid);
},

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