javascript - 如何在量角器中的套件之间共享相同的测试用例
问题描述
我有一些测试用例可以在测试套件之间共享
假设套件 x 和套件 y 共享同一组测试用例(它起作用)。
我制作了一个单独的 .js 文件,其中包含看起来像这样的共享代码。
module.exports = function(a,b){
//...
test cases..
//....
}
我正在尝试在 x 和 y 中使用这个模块
这就是 x 的样子
var common = require('./module');
describe("description", module(a,b);
可以这样做吗?还有其他方法吗?
我的代码中常见的js看起来像
module.exports = function(a,b) {
beforeAll(function(){
//some code
}
afterAll(function(){
//some code
}
It(‘ads’, function(){
code
}
it(‘ads’, function(){
code
}
it(‘ads’, function(){
code
}
}
我想在另外两个套件中将其用作带有可传递参数的 describe 函数的函数参数。
套房1
var common = ('./common');
describe('this is a test case', common(a,b);
这可能吗?
解决方案
如果您的 common.js 文件类似于...
module.exports = function(a,b){
//...
test cases..
//....
}
还有你的 test.js 文件:
var common = require('./common'); // <-- note the change
describe("description", common); // <-- you were calling module*
这是假设您的 common.js 导出函数是格式正确的描述函数。
您还可以导出单个测试用例,例如 (other.js)...
module.exports = {
testOne: function(something) { return false; },
testTwo: function(whatever) { return true; }
}
而你的测试...
var other = require('./other');
describe("description", function() {
it('should pass', function() {
expect(other.testOne()).toEqual(false);
});
});
推荐阅读
- sql - 内部加入,加入没有按预期工作
- javascript - 在 vue 应用程序中导入 chessboard.js 的问题
- android - 调用需要 API 级别 21(当前最低为 14):android.speech.tts.TextToSpeech#speak
- python - DolphinDB 中是否有任何简单的方法来完成 Python 中的**shift down** 函数?
- docker - 当我添加 GSCFuse 并在 Kubernetes 中部署我的应用程序时收到此错误消息任何建议可能是什么问题
- java - 使用 Ion 库加载返回 null JsonObject 结果
- python - 不受信任的泡菜来源
- c# - 将列字符串添加到 DataGridVIew 中每个选定行的列表中
- scala - 使用 @uncheckedVariance 强制 Scala 抽象类型的协方差
- c# - Xamarin CollectionView 与 HorizontalItemSpacing 相等的项目宽度