javascript - Passing parameters to Mocha - Stack Overflow

I am using Mocha programatically as described here:Very similarly to how the examples are written:test-

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 badges
Add a ment  | 

1 Answer 1

Reset to default 5

In 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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745247863a4618495.html

相关推荐

  • javascript - Passing parameters to Mocha - Stack Overflow

    I am using Mocha programatically as described here:Very similarly to how the examples are written:test-

    3小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信