Comments (14)
Solved.
Looking at the source of the failure message, here: https://github.com/aexmachina/factory-girl/blob/7e4335330a4e85d4c6c2ecf9a881df8ff9b77965/src/adapters/DefaultAdapter.js#L4
It looked like I just wasn't initializing the SequelizeAdapter properly, so I was hitting the DefaultAdapter. I would have noticed that earlier, but I'm running my tests in mocha and it took me forever to figure out how to get a trace from Node's UnhandledPromiseRejectionWarning via the unhandledRejection event. In case anyone else is curious, just added this to the mocha test file:
process.on('unhandledRejection', (reason, p) => {
console.log('Unhandled Rejection at: Promise', p);
console.log('reason:', reason);
});
Anyway, I just needed to call setAdapter
. Here's the working code:
var factory = require('factory-girl');
const adapter = new factory.SequelizeAdapter();
factory = factory.factory;
factory.setAdapter(adapter);
const Models = require('../../models');
factory.define('products', Models.products, {
name: 'Some Foo',
priority: 50,
});
from factory-girl.
I've published v4
from factory-girl.
@gunar, it should happen soon!
from factory-girl.
@lblazecki, if I am right, the issue is probably because of Sequelize
Model. FactoryGirl expects Model
to be a constructor function that can be used to create new instances. In case of Sequelize I guess Model.Instance
is the constructor function.
Thanks for pointing out the issue. Here is what you can do to keep things working at your end, till we get this fixed:
- update your package.json to point factory-girl to
https://github.com/chetanism/factory-girl.git#v4-sequelize-fix
- Import factory-girl from `factory-girl/dist'
- To avoid putting
factory-girl/dist
at all places, create a wrapper script in your app and import the wrapper script wherever required, once the issue is fixed, you can easily change it back to importing fromfactory-girl
I have just pushed the updated build to the above mentioned branch. This should keep you going while we fix the issue.
from factory-girl.
Hi @lblazecki, thanks for raising the issue. I suppose there are two problems to fix here: #64 and that we haven't put the new version for factory-girl-sequelize yet. Sorry for the confusion that you had to face, but we'll need another 1-2 weeks to sort everything out.
from factory-girl.
@chetanism thank you for your response :)
I am looking forward to it!
from factory-girl.
Hi @lblazecki, we just managed to fix #64 as well as add a Sequelize adapter to factory girl itself.
You should be able to:
import factory, { SequelizeAdapter } from 'factory-girl'
Let us know in case you face any issues.
from factory-girl.
Hi @chetanism
I faced an issue:
.../node_modules/factory-girl/index.js:66
throw new Error('Invalid Model constructor passed to the factory');
^
Error: Invalid Model constructor passed to the factory
This is the line in code:
if (!Model || typeof Model !== 'function') {
throw new Error('Invalid Model constructor passed to the factory');
}
When typeof Model !== 'function'
is removed it's working normally, but I am not sure what are the consequences of removing it.
from factory-girl.
Thank you :)
It's working now 👍
from factory-girl.
It seems both #63 & #64 are resolved now. Can we haz stable version?
from factory-girl.
I can't seem to get v4 working with Sequelize 3.24.4. I think npm installed factory-girl 4.0.0-beta.7.
Here's my setup:
var factory = require('factory-girl');
const adapter = new factory.SequelizeAdapter();
factory = factory.factory;
const Models = require('../../models');
factory.define('products', Models.products, {
name: 'Some Foo',
priority: 50,
});
At this point I get TypeError: Model is not a constructor
. I can't seem to find the magic incantation to get a sequelize model object that factory-girl finds kosher.
I'm using sequelize's import
method to place one model per file: http://docs.sequelizejs.com/en/latest/api/sequelize/#importpath-model
You can see an example of what that looks like here: https://github.com/sequelize/express-example/blob/master/models/task.js
Any ideas?
from factory-girl.
Hi @createthis, glad that your problem is solved. I did saw the mail for this issue, but couldn't find time to look into it. Thanks for posting the comment, it would help if someone else faces the issue.
I just have one request, if you face any issues, please open a new issue for it. Not just it would keep the discussion separate, it would also help others to find it easily if they face similar problem.
from factory-girl.
@chetanism what about now? 😇
from factory-girl.
@createthis THANK YOU SO MUCH FOR POSTING YOUR SOLUTION!!!!
from factory-girl.
Related Issues (20)
- Expose passed attrs to initializer function HOT 1
- concatonating values from chance generator
- Add to CHANGELOG that `buildSync` is gone in v4
- factory.assoc is not taking attributes values from factory.create
- Resetting Sequence HOT 1
- UnhandledPromiseRejectionWarning: TypeError: Model is not a constructor
- ENHANCEMENT: Async buildOptions on extended factory not taking the base factory values HOT 1
- afterCreate() in Sub-Object Creates Weird Error HOT 1
- make compatible mongoose 5.29 populate
- TypeScript definition HOT 5
- Calling create "hangs" during create
- Is this project still maintained? HOT 7
- Undefined attribute on initializer cause error HOT 1
- How to define @many to many ? HOT 1
- delete objects after test suite HOT 3
- Is it possible to use build options with an extended factory? HOT 1
- Invalid params when callback afterBuild and afterCreate in case create/buildMany
- How to use a factory definition in a separate file? HOT 1
- When using factory with jest and mongoose, process doesn't end HOT 1
- [DEP0128] DeprecationWarning: Invalid 'main' field HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from factory-girl.