我用Mocha来测试我的JavaScript东西。我的测试文件包含5个测试。是否可以运行一个特定的测试(或一组测试),而不是文件中的所有测试?
当前回答
使用Mocha的——fgrep(或者-f)你可以选择包含字符串的测试,例如:
mocha -f 'my test x'
将在it()、describe()或context()块中运行包含我的测试x的所有测试。
其他回答
使用Mocha的——fgrep(或者-f)你可以选择包含字符串的测试,例如:
mocha -f 'my test x'
将在it()、describe()或context()块中运行包含我的测试x的所有测试。
有多种方法可以做到这一点。
If you just want to run one test from your entire list of test cases then, you can write only ahead of your test case. it.only('<test scenario name>', function() { // ... }); or you can also execute the mocha grep command as below mocha -g <test-scenario-name> If you want to run all the test cases which are inside one describe section, then you can also write only to describe as well. describe.only('<Description of the tests under this section>', function() { // ... }); If you have multiple test files & you wanted to run only one of then you can follow the below command. npm test <filepath> eg : npm test test/api/controllers/test.js here 'test/api/controllers/test.js' is filepath.
嗨,上面的解决方案对我不起作用。 运行单个测试的另一种方法是
mocha test/cartcheckout/checkout.js -g 'Test Name Goes here'
这有助于从单个文件和特定名称运行测试用例。
你可以试试"it.only"
it.only('Test one ', () => {
expect(x).to.equal(y);
});
it('Test two ', () => {
expect(x).to.equal(y);
});
在这种情况下,只执行第一个
不知道为什么grep方法在使用npm测试时不适合我。不过这是可行的。出于某种原因,我还需要指定测试文件夹。
npm test -- test/sometest.js
推荐文章
- src和dist文件夹的作用是什么?
- jQuery UI对话框-缺少关闭图标
- 如何使用AngularJS获取url参数
- 将RGB转换为白色的RGBA
- 如何将“camelCase”转换为“Camel Case”?
- 我们可以在另一个JS文件中调用用一个JavaScript编写的函数吗?
- 如何使用JavaScript重新加载ReCaptcha ?
- jQuery。由于转义了JSON中的单引号,parseJSON抛出“无效JSON”错误
- 在JavaScript关联数组中动态创建键
- ReactJS和公共文件夹中的图像
- 在React Native中使用Fetch授权头
- 为什么我的球(物体)没有缩小/消失?
- 如何使用jQuery检测页面的滚动位置
- if(key in object)或者if(object. hasownproperty (key)
- 一元加/数字(x)和parseFloat(x)之间的区别是什么?