admin管理员组文章数量:1416051
I am using Mocha programatically as described here:
Very similarly to how the examples are written:
test-runner.js:
var Mocha = require('mocha');
var mocha = new Mocha();
mocha.addFile('spec.js');
mocha.run(function() {});
Inside the test spec, I am spinning up a headless browser to run the test on a specific url:
spec.js:
var Browser = new Browser();
browser.visit(url, function(){});
Is there a way to pass the desired url from test-runner.js to spec.js?
I am using Mocha programatically as described here:
https://github./visionmedia/mocha/wiki/Using-mocha-programmatically
Very similarly to how the examples are written:
test-runner.js:
var Mocha = require('mocha');
var mocha = new Mocha();
mocha.addFile('spec.js');
mocha.run(function() {});
Inside the test spec, I am spinning up a headless browser to run the test on a specific url:
spec.js:
var Browser = new Browser();
browser.visit(url, function(){});
Is there a way to pass the desired url from test-runner.js to spec.js?
Share Improve this question asked Dec 21, 2012 at 23:36 superdikerysuperdikery 781 silver badge6 bronze badges1 Answer
Reset to default 5In your spec file, you can require a module that contains the configurations for those tests:
var url = require('./config.js').url;
describe("blah", function(){
...
});
This config module could also be set from the initial mocha tests (e.g.):
var Mocha = require('mocha');
var mocha = new Mocha();
var config = require('./config.js');
config.setOptions({url:"localhost/testme.html"});
mocha.addFile('spec.js');
mocha.run(function() {});
Check out this related SO regarding node modules being singletons.
本文标签: javascriptPassing parameters to MochaStack Overflow
版权声明:本文标题:javascript - Passing parameters to Mocha - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745247863a2649640.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论