Unit testing 如何对使用服务的助手进行单元测试?
我正在尝试对使用服务的助手进行单元测试 这是我注入服务的方式:Unit testing 如何对使用服务的助手进行单元测试?,unit-testing,ember.js,Unit Testing,Ember.js,我正在尝试对使用服务的助手进行单元测试 这是我注入服务的方式: export function initialize(container, application) { application.inject('view', 'foobarService', 'service:foobar'); } 助手: export function someHelper(input) { return this.foobarService.doSomeProcessing(input); } e
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
一切都是正确的,唯一需要的改变是:
var result = someHelper.call(mockView, "42");