Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

javascript - 如何使用Mocha进行单个测试?(How to run a single test with Mocha?)

I use Mocha to test my JavaScript stuff.(我使用Mocha测试我的JavaScript内容。)

My test file contains 5 tests.(我的测试文件包含5个测试。) Is that possible to run a specific test (or set of tests) rather than all the tests in the file?(是否可以运行特定测试(或一组测试)而不是文件中的所有测试?)   ask by Misha Moroshko translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try using mocha's --grep option :(尝试使用mocha的--grep选项 :)

-g, --grep <pattern> only run tests matching <pattern> You can use any valid JavaScript regex as <pattern> .(您可以将任何有效的JavaScript正则表达式用作<pattern> 。) For instance, if we have test/mytest.js :(例如,如果我们有test/mytest.js :) it('logs a', function(done) { console.log('a'); done(); }); it('logs b', function(done) { console.log('b'); done(); }); Then:(然后:) $ mocha -g 'logs a' To run a single test.(运行单个测试。) Note that this greps across the names of all describe(name, fn) and it(name, fn) invocations.(请注意,这会涉及所有describe(name, fn)it(name, fn)调用的it(name, fn) 。) Consider using nested describe() calls for namespacing in order to make it easy to locate and select particular sets.(考虑使用嵌套的describe()调用来命名空间,以便于查找和选择特定集合。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...