The goal of this simple exercise is to successfully simulate and test an error condition that causes the catch block of the promise to execute.
It turns out that the setup of the test makes it almost trivial to hijack the promise and inject our own mock behavior.

Below I have created a simple Jasmine test where I'm able to successfully simulate the required error condition.

The key part is the rejectPromise method that we can pass in as part of the mock service injected into the controller. As you can tell, passing dependencies to controllers is trivial if we make use of the $controller function to instantiate the greetingController.

If you liked this article, share it with your friends on social media: