当我单独运行它时,为什么我的Ember组件集成测试通过,但是当我运行完整套件时失败?

时间:2017-07-19 13:52:16

标签: testing ember.js ember-cli qunit ember-qunit

我对一个依赖i18n服务(测试注入)的组件进行了一个简单的,简单的集成测试。组件本身是ember-select-list的简单选择下拉列表,默认值为Select Language。这是测试:

import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('language-select', 'Integration | Component | language select', {
  integration: true,
  beforeEach() {
    this.inject.service('i18n');
  }
});

test('it renders', function(assert) {
  this.render(hbs`{{language-select}}`);

  assert.equal(this.$().text().trim().includes('Select Language'), true);
});

当我尝试运行这个测试文件(即ember test -f "language-select")时,我看到的输出表明只进行了linting测试:

[ hospitalrun-frontend ] $ ember test -f "language-select"
WARNING: Node v7.5.0 is not tested against Ember CLI on your platform. We recommend that you use the most-recent "Active LTS" version of Node.js.
cleaning up...
Built project successfully. Stored in "/Users/richie.thomas/Desktop/Workspace/OpenSource/hospitalrun-frontend/tmp/core_object-tests_dist-5MT1adu7.tmp".
ok 1 PhantomJS 2.1 - ESLint - acceptance/language-select-test.js: should pass ESLint
ok 2 PhantomJS 2.1 - ESLint - components/language-select.js: should pass ESLint
ok 3 PhantomJS 2.1 - TemplateLint - hospitalrun/templates/components/language-select.hbs: should pass TemplateLint
ok 4 PhantomJS 2.1 - ESLint - integration/components/language-select-test.js: should pass ESLint

1..4
# tests 4
# pass  4
# skip  0
# fail  0

# ok

然而,当我运行普通ember test时,我发现此测试失败,因为我显然错误地注入了i18n服务:

not ok 488 PhantomJS 2.1 - Integration | Component | language select: it renders
---
    actual: >
        null
    expected: >
        null
    stack: >
        http://localhost:7357/assets/hospitalrun.js:4090:18
        get@http://localhost:7357/assets/vendor.js:35757:32
        get@http://localhost:7357/assets/vendor.js:40664:22
        compute@http://localhost:7357/assets/vendor.js:33758:29
        value@http://localhost:7357/assets/vendor.js:33625:52
        value@http://localhost:7357/assets/vendor.js:65639:37
        value@http://localhost:7357/assets/vendor.js:33512:34
        create@http://localhost:7357/assets/vendor.js:31495:53
        evaluate@http://localhost:7357/assets/vendor.js:66320:43
        execute@http://localhost:7357/assets/vendor.js:72898:36
        render@http://localhost:7357/assets/vendor.js:72472:30
        render@http://localhost:7357/assets/vendor.js:30793:52
        runInTransaction@http://localhost:7357/assets/vendor.js:41756:28
        _renderRoots@http://localhost:7357/assets/vendor.js:31058:64
        _renderRootsTransaction@http://localhost:7357/assets/vendor.js:31096:26
        _renderRoot@http://localhost:7357/assets/vendor.js:31017:35
        _appendDefinition@http://localhost:7357/assets/vendor.js:30930:23
        appendOutletView@http://localhost:7357/assets/vendor.js:30913:29
        invoke@http://localhost:7357/assets/vendor.js:19795:19
        flush@http://localhost:7357/assets/vendor.js:19865:15
        flush@http://localhost:7357/assets/vendor.js:19989:20
        end@http://localhost:7357/assets/vendor.js:20059:28
        run@http://localhost:7357/assets/vendor.js:20182:19
        run@http://localhost:7357/assets/vendor.js:40972:32
        render@http://localhost:7357/assets/test-support.js:20665:30
        http://localhost:7357/assets/tests.js:15398:16
        runTest@http://localhost:7357/assets/test-support.js:3859:34
        run@http://localhost:7357/assets/test-support.js:3845:13
        http://localhost:7357/assets/test-support.js:4037:15
        advance@http://localhost:7357/assets/test-support.js:3522:26
        begin@http://localhost:7357/assets/test-support.js:5213:27
        http://localhost:7357/assets/test-support.js:4407:11
    message: >
        Died on test #1 http://localhost:7357/assets/tests.js:15392:24
        exports@http://localhost:7357/assets/vendor.js:123:37
        requireModule@http://localhost:7357/assets/vendor.js:38:25
        require@http://localhost:7357/assets/test-support.js:19547:14
        loadModules@http://localhost:7357/assets/test-support.js:19539:21
        load@http://localhost:7357/assets/test-support.js:19569:33
        http://localhost:7357/assets/test-support.js:7584:22: undefined is not an object (evaluating 'i18n.get')
    Log: |
...

我在documentation here中没有看到任何影响运行测试类型的过滤器标志(即lint与非lint测试)。

我很高兴发布一个关于如何正确注入i18n服务的单独问题,但我的问题是:

为什么只添加filter标志只会过滤正在运行的测试?

1 个答案:

答案 0 :(得分:2)

它过滤模块名称,而不是文件名。你在一个过滤字符串中划线。删除它并使用空格:

ember test -f "language select"