我正在尝试对使用服务的助手进行单元测试。
这是我注入服务的方式:
export function initialize(container, application) {
application.inject('view', 'foobarService', 'service:foobar');
}
帮助者:
export function someHelper(input) {
return this.foobarService.doSomeProcessing(input);
}
export default Ember.Handlebars.makeBoundHelper(someHelper);
一切都在这里工作。
单元测试不了解服务并且失败。我试着:
test('it works', function(assert) {
var mockView = {
foobarService: {
doSomeProcessing: function(data) {
return "mock result";
}
}
};
// didn't work
var result = someHelper.call(mockView, 42);
assert.ok(result);
});
错误:
Died on test #1 at http://localhost:4200/assets/dummy.js:498:9
at requireModule (http://localhost:4200/assets/vendor.js:79:29)
TypeError: undefined is not a function
答案 0 :(得分:1)
一切都是正确的,唯一需要的改变是:
var result = someHelper.call(mockView, "42");