https://github.com/stefanpenner/ember-cli/issues/2421
ember-cli: 1.2
I have a boilerplate addon project that has a title-case helper as follows:
My Helper app/helpers/title-case.js
import Ember from 'ember';
export default Ember.Handlebars.makeBoundHelper(function(string) {
if (typeof string === 'string') {
//replace dashes with spaces
var str = string.dasherize().replace(/-/g, ' ');
return str.replace(/\w\S*/g, function(word){
return word.charAt(0).toUpperCase() + word.substr(1).toLowerCase();
});
} else {
return string;
}
});
I Generated the test for the helper using ember-cli
ember g helper-test title-case
This was the output:
import {
titleCase
} from 'boilerplate/helpers/title-case';
module('TitleCaseHelper');
// Replace this with your real tests.
test('it works', function() {
var result = titleCase(42);
ok(result);
});
Now running tests from ember-cli
ember test
Getting the following error:
Build failed.
File: dummy/tests/unit/helpers/title-case-test.js
ENOENT, no such file or directory '/home/me/git/ember/boilerplate/tmp/tree_merger-tmp_dest_dir-PL6HFkuw.tmp/boilerplate/helpers/title-case.js'
Error: ENOENT, no such file or directory '/home/me/git/ember/boilerplate/tmp/tree_merger-tmp_dest_dir-PL6HFkuw.tmp/boilerplate/helpers/title-case.js'
UPDATE
I tried changing the following to "dummy" instead of the autogenerated "boilerplate" and removed the curly brackets.
//import {
// titleCase
//} from 'dummy/helpers/title-case';
import titleCase from 'dummy/helpers/title-case';
it gets further now and into the test method but failed when calling titleCase(42)
with:
TypeError: Cannot read property 'isUnbound' of undefined
UPDATE #2
I was able to get this working but it is ugly, I needed to access the ._rawFunction
property and change the format of the import statement.
import titleCaseHelper from 'dummy/helpers/title-case';
var titleCase = titleCaseHelper._rawFunction;
module('TitleCaseHelper');
test('Title case lower case letters', function() {
var result = titleCase('hello world');
equal(result, 'Hello World');
});
I am still confused as to why the original generated test by ember-cli didn't work.