0

HTML を作成するヘルパーを使用する Ember コンポーネントがあり、コンポーネントとヘルパー HTML を組み合わせた結果の HTML をチェックするテストを作成しようとしています。

例...
コンポーネントは以下を生成します:<div class="one"></div>

ヘルパーは以下を生成します:<div class="two"></div>

コンバインは次のものを生成します。<div class="one"><div class="two"></div></div>

何が起こっているかというと、HTMLBars がヘルパーの HTML を生成していないということです。ヘルパーに渡された JSON 値を入力します。

したがって、テストは以下を生成します。<div class="one">true</div>

ヘルパーがアクティブであるべきだと言うために何かを含める必要がありますか?

4

1 に答える 1

2

There must be a bug in your code. It doesn't matter if your component consumes a helper or not for integration tests. I have written a short Ember Twiddle to demonstrate: https://ember-twiddle.com/a50c05ec5a050a4c72fd3c53445e3e1d

// /app/helpers/hello-world.js
import Ember from 'ember';

export function helloWorld(params/*, hash*/) {
  return new Ember.Handlebars.SafeString('<strong>Hello World!</strong>');
}

export default Ember.Helper.helper(helloWorld);

// /app/components/component-using-helper.js
import Ember from 'ember';

export default Ember.Component.extend({
  tagName: 'p'
});

// /tests/integration/components/component-using-helper.js

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

moduleForComponent('component-using-helper', 'TODO: put something here', {
  integration: true
});

test('it renders', function(assert) {
  this.render(hbs`{{component-using-helper}}`);

  assert.ok(this.$('p').length === 1);
  assert.ok(this.$('p strong').length === 1);
  assert.equal(this.$('p strong').html().trim(), 'Hello World!');
});

Test passes.

于 2016-04-14T00:07:03.067 に答える