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

How do I import and use this project as ES6 module? #9

Open
rednotice opened this issue Jan 31, 2021 · 3 comments
Open

How do I import and use this project as ES6 module? #9

rednotice opened this issue Jan 31, 2021 · 3 comments

Comments

@rednotice
Copy link

rednotice commented Jan 31, 2021

I tried to use factory-bot like this:

import factory from 'factory-bot';

factory.define('User', User, {
    name: factory.chance('name'),
    email: factory.chance('email')
});

But got an error:

TypeError: factory.define is not a function

Please help me :( How do I import and use this as ES6 modules?

@SteveDeWald
Copy link

I'm having the same issue. This code mirrors the tutorial, so I'm confused.

@HromayaHorse
Copy link

Hi! Try to import factory with this way:

const factory = require('factory-bot').factory;

it worked on me. Also don't forget to create a model as well

@metal450
Copy link

metal450 commented Jun 30, 2022

I'm having a similar issue, but it's with factory.FactoryGirl is not a constructor:

const FactoryBot = require('factory-bot')
const factory = FactoryBot.factory
const pgFactory = new factory.FactoryGirl() // Reports factory.FactoryGirl is not a constructor

Identical code worked previously with factory-girl, just trying to replace factory-girl w/ factory-bot, but am stuck with the above.

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

4 participants