James
James

Reputation: 607

Mocha Grep Regex for specific test

I have the following project https://github.com/invertednz/mocha-example

It has 4 tests:

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

I want to use --grep so that I only run "should return -1 when the value is not present"

I wanted to use "^should return -1 when the value is not present$" but I believe the describe section messes this up.

The above represents a somewhat contrived example, I am being returned a testname that I need to run from an api and then I just want to run that specific test, I am unsure of all the test names that maybe present.

For example I would in this case know that I want to run 'should return -1 when the value is not present' but not know that 'starts should return -1 when the value is not present' exists.

I was wondering if I could use the describe like:

Array #indexOf().should return -1 when the value is not present$

What regex should I use?

Upvotes: 0

Views: 1012

Answers (1)

Chris
Chris

Reputation: 2304

For this specific set of strings you could use something as simple as:

^(?!starts).*present$

Which would simply ensure that the first string is not matched by using a negative lookahead while the 3rd and 4th strings are not matched due to the match ending immediately after present.

Upvotes: 1

Related Questions