Running single karma test fails with mongoose error MissingSchemaError: Schema hasn't been registere

Skip to first unread message

Venci Vatashki

unread,
Nov 12, 2015, 9:45:23 AM11/12/15
to MEAN.JS
I am using latest development master branch of meanjs with WebStorm for IDE. Last version of WebStorm support running/debugging single karma test from IDE. Unfortunately meanjs breaks with a mongoose error "MissingSchemaError: Schema hasn't been registered for model "User"."
This should be something with js order of parsing file/ missing require() call/ or not providing karma.conf.js.

This is the new call that fails:
"C:\Program Files\nodejs\node.exe" C:\projects\node\meanjs\node_modules\mocha\bin\_mocha --ui bdd --reporter "C:\Program Files (x86)\JetBrains\WebStorm 11.0\plugins\NodeJS\js\mocha-intellij\lib\mochaIntellijReporter.js" C:/projects/node/meanjs/modules/articles/tests/server/article.server.model.tests.js --grep "Article Model Unit Tests\: Method Save should be able to save without problems$"


You can safely remove --reporter option if you don't have WebStorm.  It will fail again :)

Running karma:unit grunt task works:
"C:\Program Files\nodejs\node.exe" C:\projects\node\meanjs\node_modules\grunt-cli\bin\grunt --gruntfile C:\projects\node\meanjs\gruntfile.js karma:unit

Error stack trace is 

C:\projects\node\meanjs\node_modules\mongoose\lib\index.js:333
      throw new mongoose.Error.MissingSchemaError(name);
            ^
MissingSchemaError: Schema hasn't been registered for model "User".
Use mongoose.model(name, schema)
    at Mongoose.model (C:\projects\node\meanjs\node_modules\mongoose\lib\index.js:333:13)
    at Object.<anonymous> (C:\projects\node\meanjs\modules\articles\tests\server\article.server.model.tests.js:8:19)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at C:\projects\node\meanjs\node_modules\mocha\lib\mocha.js:172:27
    at Array.forEach (native)
    at Mocha.loadFiles (C:\projects\node\meanjs\node_modules\mocha\lib\mocha.js:169:14)
    at Mocha.run (C:\projects\node\meanjs\node_modules\mocha\lib\mocha.js:356:31)
    at Object.<anonymous> (C:\projects\node\meanjs\node_modules\mocha\bin\_mocha:366:16)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3

Thanks for any feedback 


laure....@playjugo.com

unread,
Nov 13, 2015, 3:43:09 AM11/13/15
to MEAN.JS
Hi,

You need to start the database before inserting the model, then to resolve that use this:

var connection = require (your connection file),

then in your main method:

connection.on("connected", function(ref) {

//Add your var model

}

Regards.
Reply all
Reply to author
Forward
0 new messages