Reputation: 53335
I am using Mocha to write BDD tests in browser. I would like the ability to run selective tests using Mocha's grep option. Mocha has grep support when launched from command line for node.js environment. However I can't get it to work for the browser.
I am setting up Mocha as shown in these example html file and tried to pass grep as option, but that didn't work
mocha.setup({ui:"bdd",ignoreLeaks:true,grep:"pattern"})
mocha.run()
Any ideas?
Upvotes: 3
Views: 1346
Reputation: 53335
Ok, I figured it out.
You can mention the grep option in the URL like this
/?grep=pattern
If you want to launch tests programmatically you need to make sure that window.location.search
reads ?grep=pattern
.
Directly setting window.location.search to some string may not be desirable because that refreshes the page. Instead you can use HTML5 history API window.history.pushState({},'Test','/?grep=pattern')
before calling mocha.run()
Upvotes: 4