title: AngularJs Unit Tests with Jasmine and RequireJs
body: <p>I am having trouble getting unit tests working for an Angular JS app using Jasmine and RequireJs. I have created a Plunker <a href="http://plnkr.co/edit/h3Azyc" rel="nofollow">here</a></p>
  
  <p>The problem I am having is around the creation of a module. If I include the setup for the Angular module in my controller, like so (see Controller.js in Plunker):</p>
  
  <pre><code>angular.module('catalogManagementApp', []);
  </code></pre>
  
  <p>then everything works fine. However, this module is created in another file, so this won’t work. So if I try and setup the module in my test using the Angular Mocks module function I get an error saying "No module: catalogManagementApp".</p>
  
  <p>If you look at the ControllerTests.js file, this makes sense because RequireJS is loading the Controller before my call to Angular Mocks to create the module:</p>
  
  <pre><code>beforeEach(module('catalogManagementApp'));
  </code></pre>
  
  <p>However, I am not sure how to get this working. As you can see from the commented out code in the ControllerTests.js file I have tried moving the require call for the Controller to after the call to setup the module, but this causes the Jasmine test runner to fail and still the same no module error.</p>
  
  <p>The running of Jasmine with RequireJs code was adapted from <a href="http://kilon.org/blog/2012/08/testing-backbone-requirejs-applications-with-jasmine/" rel="nofollow">this</a></p>