samedi 28 février 2015

How do I unit test a helper that uses a service?

I'm trying to unit test a helper that uses a service.


This is how I inject the service:



export function initialize(container, application) {
application.inject('view', 'foobarService', 'service:foobar');
}


The helper:



export function someHelper(input) {
return this.foobarService.doSomeProcessing(input);
}

export default Ember.Handlebars.makeBoundHelper(someHelper);


Everything works until here.


The unit test doesn't know about the service and fails. I tried to:



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);
});




Aucun commentaire:

Enregistrer un commentaire