We have a lot of code in our project that isn't covered because of ember concurrency tasks.
Is there a straightforward way of unit testing an controller that contains something like the following:
export default Controller.extend({
updateProject: task(function* () {
this.model.project.set('title', this.newTitle);
try {
yield this.model.project.save();
this.growl.success('success');
} catch (error) {
this.growl.alert(error.message);
}
})
});```
You can unit test a task like that by calling
someTask.perform(). For the given task you can stub what you need to in order to test it thoroughly:This is using spies from sinon and ember-sinon-qunit to access sinon from a test context, but these are not necessary for unit testing. You could stub the model and services, etc. with assertions instead of spies:
To test the catch you can throw from your stubbed
model.project.save()method: