Skip to content
This repository has been archived by the owner on Feb 6, 2021. It is now read-only.

Latest commit

 

History

History
60 lines (44 loc) · 2.26 KB

File metadata and controls

60 lines (44 loc) · 2.26 KB

ember-cli-htmlbars-inline-precompile

npm version Build Status Build Status Ember Observer Score Dependency Status

Precompile template strings within the tests of an Ember project via tagged template strings:

// ember-cli-project/test/unit/components/my-component-test.js
import { module, test } from 'qunit';
import { render } from '@ember/test-helpers';
import { setupRenderingTest, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

module('my-component', function(hooks) {
  setupRenderingTest(hooks);

  test('it renders', async function(assert) {
    await render(hbs`hello ember testing!`);

    assert.equal(this.element.innerText, 'hello ember testing!');
  });
});

Requirements

  • Ember 2.12+
  • Node 8+
  • Babel 7+

Installation

Install the addon via ember install ember-cli-htmlbars-inline-precompile

Caveats

Keep in mind that the source files are transformed, so the inline template definitions are replaced with Ember.HTMLBars.template(…) statements. This means that you can't do fancy stuff like string interpolation within the templates:

test('string interpolation within templates is NOT supported', async function(assert) {
  let valuePath = 'greeting';

  await render(hbs`
    ${valuePath}: <span>{{value}}</span>
  `);

  // the template will be "${valuePath}: <span>{{value}}</span>"
});

If you need stuff like this, you need to include ember-template-compiler.js in your test-build and use Ember.HTMLBars.compile("…") within your tests.