Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ember.js 使用Ember CLI对Ember日期选择器组件进行验收测试_Ember.js_Ember Cli_Acceptance Testing - Fatal编程技术网

Ember.js 使用Ember CLI对Ember日期选择器组件进行验收测试

Ember.js 使用Ember CLI对Ember日期选择器组件进行验收测试,ember.js,ember-cli,acceptance-testing,Ember.js,Ember Cli,Acceptance Testing,我正在使用Pikaday在Ember CLI项目中创建一个Ember日期选择器组件。似乎不可能在组件测试中测试用户交互。有人知道怎么做吗 例如,我试图测试在单击组件的输入时是否显示Pikaday小部件。测试如下所示: import { test, moduleForComponent } from 'ember-qunit'; moduleForComponent('datepicker-input'); test('is an input tag', function() { equa

我正在使用Pikaday在Ember CLI项目中创建一个Ember日期选择器组件。似乎不可能在组件测试中测试用户交互。有人知道怎么做吗

例如,我试图测试在单击组件的输入时是否显示Pikaday小部件。测试如下所示:

import { test, moduleForComponent } from 'ember-qunit';

moduleForComponent('datepicker-input');

test('is an input tag', function() {
  equal('INPUT', this.$().prop('tagName'));
});

test('clicking the input opens the pikaday dialog', function() {
  ok($('.pika-single').hasClass('is-hidden'));
  click(this.$().find('input'));
  ok(!$('.pika-single').hasClass('is-hidden'));
});
由于
参考错误:未定义单击,第二次测试失败。我不知道我做错了什么,据我所知,我的测试与Ember.js网站上的示例相同:


所以我猜问题也可能出在Ember CLI上。欢迎提供任何帮助,我愿意接受如何测试组件的用户交互的建议。

您需要将组件添加到DOM中

test('clicking the input opens the pikaday dialog', function() {
    $input = this.append();

    ok($('.pika-single').hasClass('is-hidden'));
    click('#your-input').then(function() {
        ok(!$('.pika-single').hasClass('is-hidden'));
    });
});

我认为您需要在运行测试之前调用
App.setupForTesting
,在旧版本的ember中,还需要调用
App.injectTestHelpers


您还需要调用this.append以使组件显示在DOM中。

我最终手动启动并销毁了应用程序。此外,每次手动测试后,我也会拆卸部件。这是必要的,直到从Ember CLI中的QUnit插件土地进行一些上游更改


您可以在GitHub上查看完整的测试文件:

在什么版本的Ember中出现了这个问题?我用自动生成的组件测试进行了测试,测试方式与我在ember插件(ember 2.4.3)上使用ember应用程序进行测试的方式几乎相同


这使用jQuery中的
单击
方法,而不是Ember.js提供的集成测试助手。所以,这并不是我想要完成的。Ok修复了使用集成测试助手的问题。请注意,它需要一个选择器,而不是一个元素。正如我的问题所述,问题在于未定义
单击
集成测试帮助程序。Ember 1.7不再使用本地测试帮助程序。正如Stanley所说,通过调用App.setupForTesting()和App.injectTestHelpers()确保它们被注入。在ember cli中,这应该在tests/helpers/start-app.js中为您完成
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('image-item', 'Integration | Component | image item', {
     integration: true
});

test('it renders an image with alt', function(assert) {
    this.set('src', 'image.png');
    this.set('alt', 'grandmother');

    this.render(hbs`{{image-item src=src alt=alt}}`);

    assert.equal(this.$('img').attr('src'), 'image.png');
    assert.equal(this.$('img').attr('alt'), 'grandmother');
});