taylonr
taylonr

Reputation: 10790

How do I resolve a "script error" for RequireJS and Jasmine?

I was trying to follow this blog about using requirejs and jasmine in a separate assembly in an ASP.NET MVC application.

This is my SpecRunner.html:

<link rel="shortcut icon" type="image/png" href="lib/jasmine-1.3.1/jasmine_favicon.png">
  <link rel="stylesheet" type="text/css" href="lib/jasmine-1.3.1/jasmine.css">
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine.js"></script>
  <script type="text/javascript" src="lib/jasmine-1.3.1/jasmine-html.js"></script>

    <script type="text/javascript" src="../Beryllium.Web/Scripts/require.js"></script>

  <!-- include source files here... -->

  <!-- include spec files here... -->

  <script type="text/javascript">
      require.config({
          baseUrl: '../Beryllium.Web/App/ViewModels',
          paths: {
              spec: '../../Beryllium.Web.UnitTests/spec'
          }
      })
  </script>

  <script type="text/javascript">
      require(['spec/PlayerSpec', 'spec/SpecHelper'], function() {
          var jasmineEnv = jasmine.getEnv();
          jasmineEnv.updateInterval = 1000;

          var htmlReporter = new jasmine.HtmlReporter();

          jasmineEnv.addReporter(htmlReporter);

          jasmineEnv.specFilter = function(spec) {
              return htmlReporter.specFilter(spec);
          };

          var currentWindowOnload = window.onload;

          window.onload = function() {
              if (currentWindowOnload) {
                  currentWindowOnload();
              }
              execJasmine();
          };

          function execJasmine() {
              jasmineEnv.execute();
          }

      });
  </script>

Beryllium.Web is the MVC application and Beryllium.Web.UnitTests is my test assembly.

As I load the SpecRunner file and I have 2 errors on my page:

GET file:///D:/code/Beryllium/Beryllium.Web/Beryllium.Web.UnitTests/spec/PlayerSpec.js  require.js:1880
Uncaught Error: Script error for: spec/PlayerSpec
http://requirejs.org/docs/errors.html#scripterror 

And the same error for SpecHelper.js

My PlayerSpec.js starts like this:

define(['Player', 'Song'], function(Player, Song) {
    describe("Player", function() {
        var player;
        var song;

        beforeEach(function() {
            player = new Player();
            song = new Song();
        });

Is there a way to find out what exactly is causing this error? When I load the SpecRunner file, the page is blank and I only see this error by opening the console.

Upvotes: 1

Views: 8195

Answers (1)

taylonr
taylonr

Reputation: 10790

Stupid error on my part. In my require config section, I had '../../Beryllium.Web.UnitTests' but that wasn't enough directories up, so it was looking in the wrong path for the files.

Upvotes: 4

Related Questions