angularjs - Karma + Jasmine: Usage of constant like objects -


in short: put hard-coded values separate file , use them multiple test specs.

in detail: i’m doing angularjs tutorial try write cleaner code. in step 5, introduce hard-coded strings "nexus s". put such hard-coded strings separate file, example:

var testconstants = function() {     this.nexus_s = 'nexus s'; }; module.exports = new testconstants(); 

this working fine protractor tests in following way:

var constants = require('../ test-constants.js'); //… expect(…).toequal(constants.nexus_s); 

but not working unit tests (require(…) not available). tried add file karma.conf still can’t reference it.

how can reference file in similar fashion e2e protractor tests? or: best practice this?

insert file in files list in karma first one.

change following:

// wrap in function not pollute global namespace (function(){    var testconstants = function() {     this.nexus_s = 'nexus s';   };    // instance want export   var constants = new testconstants();    // if module.export available ( nodejs? ) go it,   // otherwise append global object   if (module && module.exports) {     module.exports = constants;   } else {     window.constants = constants;   }  })(); 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -