我有以下项目 https://github.com/invertednz/mocha-example
它有 4 个测试:
starts should return -1 when the value is not present
should return -1 when the value is not present
should return -1 when the value is not present2
should return -1 when the value is not present 3
我想使用 --grep,这样我只运行"当值不存在时应该返回 -1"
我想使用"^应该在值不存在时返回-1$",但我相信描述部分搞砸了。
上面代表了一个有点人为的例子,我被返回了一个我需要从 api 运行的测试名称,然后我只想运行该特定测试,我不确定可能存在的所有测试名称。
例如,在这种情况下,我会知道我想运行"当值不存在时应该返回-1",但不知道"当值不存在时,开始应该返回-1"存在。
我想知道我是否可以使用以下描述:
Array #indexOf().should return -1 when the value is not present$
我应该使用什么正则表达式?
对于这组特定的字符串,您可以使用像以下这样简单的东西:
^(?!starts).*present$
这将简单地确保第一个字符串不会通过使用负前瞻来匹配,而第 3 个和第 4 个字符串由于匹配在 present
之后立即结束而不匹配。