javascript - Check for node modules being loaded using jasmine-node -


so i'm trying teach myself jasmine (for node) working through tutorial mongoose project, tdd style, writing tests each step supposed accomplish, following actual tutorial, etc.

of course, first test failing.

app.js @ point 2 lines:

var mongoose = require('mongoose'); console.log(mongoose.version); 

this runs fine. test however, still fails:

var app = require('../src/app.js');  describe('app startup', function() {     it('loads mongoose', function() {             expect(app.mongoose.version).tobedefined();     });     it('loads jasmine-jquery', function() {             expect($).tobedefined();     }); }); 

results in

failures:  1) app startup loads mongoose message:  typeerror: cannot read property 'version' of undefined stacktrace:  typeerror: cannot read property 'version' of undefined @ null.<anonymous> (/home/jbhelfrich/mongooseblog/spec/init.spec.js:5:36) 

(the jquery test is, of course, expected fail still @ point.) i've tried , without 'app.' in expect clause, same error--the test suite doesn't see internals of app.js. know it's loading app.js file correctly, because it's running it--the console.log output appears ahead of test results.

so suspect i've misunderstood fundamental scope, or other rookie mistake, i'm not sure is.

node.js structured modules. if want a module's properties accessible, module's properties must defined in module.exports variable. export might (note exports references module.exports):

var mongoose = require('mongoose'); console.log(mongoose.version); exports.mongoose = mongoose; 

then when you've used require() on file code shown above, variables set, app equivalent module.exports in module being loaded:

var app = require('../src/app.js'); console.log(app.mongoose.version); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -