factory-girl: TypeError: Model is not a constructor (mongoose
factory-girl version 4.2.2
I think this is related to #63. I am using Mongoose but otherwise used the same set up suggested there.
var fg = require('factory-girl');
var adapter = new fg.MongooseAdapter();
factory = fg.factory;
factory.setAdapter(adapter);
When running npm test I get:
TypeError: Model is not a constructor
at MongooseAdapter.build (/Users/stoebelj/freecodecamp/voting/node_modules/factory-girl/index.js:703:14)
at Factory._callee2$ (/Users/stoebelj/freecodecamp/voting/node_modules/factory-girl/index.js:155:33)
at tryCatch (/Users/stoebelj/freecodecamp/voting/node_modules/regenerator-runtime/runtime.js:63:40)
at Generator.invoke [as _invoke] (/Users/stoebelj/freecodecamp/voting/node_modules/regenerator-runtime/runtime.js:337:22)
at Generator.prototype.(anonymous function) [as next] (/Users/stoebelj/freecodecamp/voting/node_modules/regenerator-runtime/runtime.js:96:21)
at step (/Users/stoebelj/freecodecamp/voting/node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)
at /Users/stoebelj/freecodecamp/voting/node_modules/babel-runtime/helpers/asyncToGenerator.js:28:13
Am I missing something?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 15 (2 by maintainers)
In my case I cleared many errors including this one after correcting this: module.export to module.exports đ
And I spent an hour or so just to find out that I wrote exports.module instead of module.exportsâŚ
Sometimes is the way you call the model from the controller.
If you call it like below, then it will tell you that kind of issues const { modelRes }= require(ââŚ/models/anyModelâ);
But if instead you use something like without the braces:
const modelRes = require(ââŚ/models/anyModelâ);
Then it should work fine.
Regards,
I have the same issue
When I call
const something = new Thing({name:'Stone',category:'objects'});I getTypeError: Thing is not a constructorhas anyone found a fix?
I have the same experience, found out I forget the (s) on module.exports.
here also iâm facing the same situation ,can anyone solve this?
this is the code: `var mongoose=require(âmongooseâ); mongoose.connect(âmongodb://localhost/catappâ);
var catdetails = new mongoose.details({ name:String, age:Number, breed:String }); var Cat=mongoose.model(âCatâ,catdetails);
var george=new Cat({ name:âgeorgeâ, age:11, breed:âgrouchyâ }); george.save(function(err,cat){ if(err){ console.log(âsomething Wrongâ); } else{ console.log(âwe had done it!â); console.log(cat); } });`
this is error:
TypeError: mongoose.details is not a constructor at Object.<anonymous> (/home/ubuntu/workspace/database/cat.js:4:18) at Module._compile (module.js:570:32) at Object.Module._extensionsâŚjs (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) at Module.runMain (module.js:604:10) at run (bootstrap_node.js:389:7) at startup (bootstrap_node.js:149:9) at bootstrap_node.js:504:3