title: how to reset a requirejs module between unit tests
body: <p>I have a JavaScript project which I want to observe the TDD methodology. I chose the karma framework and requirejs library for this and followed an example demonstrated in the karma docs <a href="http://karma-runner.github.io/0.8/plus/RequireJS.html" rel="noreferrer">here</a>.</p>
  
  <p>There is an example of one unit-test file, which is:</p>
  
  <pre><code>define(['app', 'jquery', 'underscore'], function(App, $, _) {
  
      describe('just checking', function() {
  
          it('works for app', function() {
              var el = $('&lt;div&gt;&lt;/div&gt;');
  
              var app = new App(el);
              app.render();
  
              expect(el.text()).toEqual('require.js up and running');
          });
  
          it('works for underscore', function() {
              // just checking that _ works
              expect(_.size([1,2,3])).toEqual(3);
          });
  
      });
  
  });
  </code></pre>
  
  <p>The main problem with this approach is that there is no way to clear the App module for each test. So if there are some changes in the App (like closure variables changes etc.) in one <code>it</code> call, then they can affect other <code>it</code> call.</p>
  
  <p>Could anyone suggest something on this? These are such popular tools, I can't believe no one ever ran into such a situation.</p>
  
  <p>So, to recapitulate the question, I would like to ask for an answer for any of these more specific ones:</p>
  
  <ul>
  <li>is there any way to "reset" (clear) module in requirejs? (<strong>actually, I suppose that there is no such a way, except reload all modules once again</strong>)</li>
  <li>is there any better approach to run karma and requirejs, so that modules do not have any remains (side effects) of other tests (<code>it</code> function calls) on them ?</li>
  </ul>