0

I have an Ember component that uses a helper that creates HTML and I am trying to create a test that checks the HTML that results from the combined component and helper HTML.

Example...
component produces:<div class="one"></div>

helper produces:<div class="two"></div>

the combine produces:<div class="one"><div class="two"></div></div>

What is happening is that HTMLBars is not producing the helper's HTML. It does input the JSON value fed into the helper.

So the test produces:<div class="one">true</div>

Do I need to included something to say that the helper should be active?

Micki T
  • 71
  • 5

1 Answers1

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.

jelhan
  • 6,149
  • 1
  • 19
  • 35
  • yes, i found an error in my json that i hadn't noticed before. thank you so much! and thanks for deciphering my code i had trouble getting the code block to work. – Micki T Apr 15 '16 at 13:45