【发布时间】:2020-10-13 09:41:31
【问题描述】:
我有两个包含两种类型标签(填充和测试)的步骤定义
- 第一步 def - cars.ts 包含以下标签:@populate_cars1、@cars1、@populate_cars2、@cars2。
- 第二步 def - clients.ts 包含以下标签:@populate_clients1、@clients1、@populate_clients2、@clients2。
在钩子中我有以下定义:
-> Before("not @populate_cars1 and not @populate_cars2 and not @populate_clients1 and not @populate_clients2", function(){...}) - 按预期工作
-> After("not @cars1 and not @cars2 and not @clients1 and not @clients2", function(){...}) - 按预期工作。
我想组织如下标签:
let pop_car = "not @populate_cars1 and not @populate_cars2"
let pop_client = "and not @populate_clients1 and not @populate_clients2"
@Before(pop_car + pop_client, function(){...})
我为每个步骤定义一个变量,其中包含标签之间的操作并将变量连接起来以获取字符串。
问题是当我连接变量“pop_car + pop_client”时 - 钩子 @Before 被调用。
【问题讨论】:
-
你能添加一个连接变量的例子吗?如果可能的话,终端日志显示@Before 被调用?
-
变量在@Before 中连接,如上。另外,我尝试在调用@Before 之前连接变量并将字符串添加到@Before。
let pop_car = "not @populate_cars1 and not @populate_cars2" let pop_client = "and not @populate_clients1 and not @populate_clients2" Before("pop_car+pop_client", function () { console.log("init db before test") return populateDB('development', true) })在每次测试前我都看到了控制台日志。 -
我不太明白这是什么问题?您正在调用 @Before 并调用钩子。我理解对了吗?
-
是的。如果我输入 'Before("not @populate_cars1 而不是 @populate_cars2 而不是 @populate_clients1 而不是 @populate_clients2", function(){...})' - 它按预期工作。在这种情况下,@Before 有来自功能 Car 和 Clients 的 4 个标签。我想要@Before(_before),_before = tagsCar + tagsClient。在这种情况下,
@Before没有按预期工作。提前谢谢! -
试试
Before("pop_car" + " " + "pop_client")。 (在它们之间添加一个空格)
标签: node.js cucumber gherkin cucumberjs