Ember qunit测试被调用两次

时间:2017-01-12 22:38:46

标签: qunit ember-qunit ember-testing

我最近升级了我的" 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。

我的Index.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>

1 个答案:

答案 0 :(得分:0)

我发现我的测试存在问题。我试图配置基于我在运行测试时发送的查询参数加载的测试集。我试图做的方式基本上是错误的。

在我的test-helper.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 helper方法时遇到以下错误:

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);
    });
});

我正在使用非常经典的版本的ember&#34; 1.10.1&#34;。不确定它是否是由它引起的!可以使用一些帮助来解决它。也发布在这里:https://github.com/ember-cli/ember-cli/issues/6293