【问题标题】:How to change qunit theme / layout如何更改 qunit 主题/布局
【发布时间】:2015-05-08 18:55:16
【问题描述】:

我最近开始使用 QUnit 来测试网页的客户端。

我对 QUnit 附带的默认布局有两个问题。 (见图)

1 : 默认消耗所有失败的测试。我希望它们默认折叠。

2 : 我想要一个下拉菜单来按模块过滤测试。

以下网页上的主题没有这些问题。 http://bryce.io/qunit-theme-burce/test/

这里是“安装”这个主题的页面。 https://github.com/brycedorn/qunit-theme-burce

但是,我无法让它工作。可能是因为我不明白安装的第一步。但是做第二个和第三个很容易。

我确实在网页中链接了主题 css,并删除了基础 css,但这不起作用。

当我使用这个样式表时, 没有隐藏,也没有显示测试。

我怎样才能让它工作以解决我的两个基本布局问题?

【问题讨论】:

  • 通过@Sergey 的回答,我发现它不起作用,因为我在文件“qunit-theme-burce.css”中的内容完全错误。这根本不是CSS。我重新下载了正确的文件。

标签: html css qunit


【解决方案1】:

要安装您指定的 QUnit 自定义主题,请将以下标签放在您的测试页面上:

<!-- theme styles -->
<link rel="stylesheet" href="path/to/qunit-theme-burce.css">

<!-- qunit source code -->
<script src="path/to/qunit.js"></script>

<script>
    function getPreviousTests( rTestName, rModuleName ) {
     // copy this function from https://github.com/brycedorn/qunit-theme-burce/blob/master/test/test.js
    }
</script>

但在您的情况下,此自定义主题不是必需的。

要隐藏失败的测试,您可以使用QUnit.testDone 方法:

  <script>
    QUnit.testDone(function(args){
        if(args.failed) {
            document.querySelector("#qunit-test-output-" + args.testId + " .qunit-assert-list").className += " qunit-collapsed";
        }
    });
  </script>

此外,如果您将QUnit 版本升级到最新版本 (1.18.0),您可以解决第二个问题。在这个版本中,模块过滤器“开箱即用”。

【讨论】:

  • QUnit.testDone 成功地折叠了所有失败的测试。我用 $('.fail .qunit-assert-list').addClass('qunit-collapsed');
  • 也感谢您指出我的 QUnit 版本也不是最新的。更新我的版本确实添加了缺少的“模块过滤器”。
猜你喜欢
  • 2014-06-30
  • 2023-04-01
  • 2022-09-24
  • 1970-01-01
  • 1970-01-01
  • 2016-09-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多