【问题标题】:How to make Mocha's grep option work in browser如何让 Mocha 的 grep 选项在浏览器中工作
【发布时间】:2012-08-15 01:23:49
【问题描述】:

我正在使用 Mocha 在浏览器中编写 BDD 测试。我希望能够使用 Mocha 的 grep 选项运行选择性测试。从 node.js 环境的命令行启动时,Mocha 支持 grep。但是我无法让它在浏览器上工作。

我正在设置 Mocha,如这些 example html 文件中所示,并尝试将 grep 作为选项传递,但这不起作用

mocha.setup({ui:"bdd",ignoreLeaks:true,grep:"pattern"})
mocha.run()

有什么想法吗?

【问题讨论】:

    标签: javascript testing mocha.js


    【解决方案1】:

    好的,我想通了。

    您可以像这样在 URL 中提及 grep 选项

    /?grep=pattern
    

    如果您想以编程方式启动测试,您需要确保 window.location.search 读取为 ?grep=pattern

    直接将 window.location.search 设置为某个字符串可能是不可取的,因为这会刷新页面。相反,您可以在调用 mocha.run() 之前使用 HTML5 历史 API window.history.pushState({},'Test','/?grep=pattern')

    【讨论】:

    • 单击浏览器中的一个测试套件条目(由 describe 块创建)会导致使用 grep 重新加载页面。可以看到 grep 模式使用并组合嵌套的 describe 块名称。
    猜你喜欢
    • 1970-01-01
    • 2016-01-08
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 1970-01-01
    • 1970-01-01
    • 2015-04-08
    • 2018-10-29
    相关资源
    最近更新 更多