我有以下项目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”,但我相信describe部分将其弄乱了。
以上内容代表了一个有些人为的例子,正在向我返回一个我需要从api运行的测试名称,然后我只想运行该特定测试,但不确定是否存在所有测试名称。
例如,在这种情况下,我想知道我想运行“当不存在该值时应返回-1”,但不知道“启动应在不存在该值时返回-1”。
我想知道是否可以使用以下描述:
Array #indexOf().should return -1 when the value is not present$
我应该使用什么正则表达式?
答案 0 :(得分:1)
对于这组特定的字符串,您可以使用以下简单内容:
^(?!starts).*present$
这将仅通过使用否定超前来确保不匹配第一个字符串,而由于匹配在present
之后立即结束,因此不匹配第3个和第4个字符串。