余烬 qunit 测试被调用两次



我最近将"ember-cli"升级到"2.10.0",将"ember-cli-qunit"升级到"3.0.1",但每个测试模块运行两次。但是,当我在jsbin中尝试代码时,我无法重现该问题。我的测试如下所示:

import Qunit from 'qunit';
Qunit.module("[Reporting]", function (hooks) {
    hooks.before(function () {
        console.log("before");            
    });
    hooks.after(function () {
        console.log("after");            
    });
    Qunit.test("test 1", function (assert) {
        console.log("test 1");  
        assert.equal(1,1);
    });
    Qunit.test("test 2", function (assert) {
        console.log("test 2"); 
        assert.equal(1,1);
    });
}

我可以看到我的 quint 版本是 2.1.1,jquery 版本是 1.11.3。

我的索引.html文件如下所示;

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Studio Tests</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    {{content-for 'head'}}
    {{content-for 'test-head'}}
    <link rel="stylesheet" href="assets/vendor.css">
    <link rel="stylesheet" href="assets/studio-blessed1.css">
    <link rel="stylesheet" href="assets/studio.css">
    <link rel="stylesheet" href="assets/test-support.css">
    <style>#blanket-main { position: relative; z-index: 99999; }</style>
    {{content-for 'head-footer'}}
    {{content-for 'test-head-footer'}}
  </head>
  <body>
    {{content-for 'body'}}
    {{content-for 'test-body'}}
    <script src="assets/vendor.js"></script>
    <script src="assets/test-support.js"></script>
    <script src="assets/studio.js"></script>
    <script src="assets/blanket-options.js"></script>
    <script src="assets/blanket-loader.js"></script>
    <script src="testem.js"></script>
    <script src="assets/tests.js"></script>
    {{content-for 'body-footer'}}
    {{content-for 'test-body-footer'}}
  </body>
</html>

我发现我的测试有问题。我正在尝试配置一组测试,这些测试将根据我在运行测试时发送的查询参数加载。我试图这样做的方式基本上是错误的。

在我的测试助手.js中,我添加了:

import Resolver from 'studio/resolver';
import {setResolver} from 'ember-qunit';
import TestLoader from 'ember-cli-test-loader/test-support';
setResolver(Resolver.create());
//ADDED THIS PROTOTYPE AS PER MENTIONED IN https://github.com/ember-cli/ember-cli-test-loader
TestLoader.prototype.shouldLoadModule = function(moduleName) {
    //return (moduleName.match(/[-_]test$/));
    var additionalCondition = true;
    var dirName = QUnit.urlParams.directory;
    if (dirName) {
        additionalCondition = moduleName.indexOf(dirName + '/') === 0 && (moduleName.indexOf('/', dirName.length + 1) === -1);
    }
    return additionalCondition;
};
TestLoader.load();

但相反,我不得不做:

import Ember from 'ember';
import resolver from './helpers/resolver';
import {
    setResolver
} from 'ember-qunit';
import TestLoader from 'ember-cli-test-loader/test-support';
Ember.$(document).ready(function () {
    TestLoader.prototype.shouldLoadModule = function (moduleName) {
        //return (moduleName.match(/[-_]test$/));
        var additionalCondition = true;
        var dirName = QUnit.urlParams.directory;
        if (dirName) {
            additionalCondition = moduleName.indexOf(dirName + '/') === 0 && (moduleName.indexOf('/', dirName.length + 1) === -1);
        }
        return additionalCondition;
    };
});
setResolver(resolver);

但是现在我在调用 andThen 帮助程序方法时出现以下错误:

Assertion after the final `assert.async` was resolved

所以:

//THIS FAILS(BUT USED TO WORK BEFORE QUINT UPGRADE)
test("DUMMY TEST 2", function (assert) {
    clickSomeElement();
    andThen(()=> {
        assert.equal(1, 1);
    });
});

我正在使用非常经典的余烬"1.10.1"版本。不知道是不是它造成的!可以使用一些帮助来解决它。张贴在这里也: https://github.com/ember-cli/ember-cli/issues/6293

相关内容

  • 没有找到相关文章

最新更新