Using requirejs with jasmine to load scripts returning 404

I am using Backbonejs and I am using require.js to load each dependent mainline widget before starting my application and put everything in a custom namespace, in this case "Foo". I would like Jasmine to download this loader file and take all the dependent javascripts (located in / public / js of my main application), however I get all 404s since Jasmine is unaware of / public / js on port 8888. How can I get jasmine to download these javascripts?

  Foo = {}; 
  jQuery(function(){
    var include = ['/js/widget.js','/js/delta_widget.js','/js/inbox.js','/js/time_widget.js','/js/high_stock_widget.js','/js/daily_summary_widget.js'];
    require(include,function(){
      $.getScript('/js/app.js');
    }); 
  });

      

For each of the javascripts I get: Failed to load resource: server responded with status 404 (not found) http://0.0.0.0:8888/js/widget.js

+3


source to share


1 answer


It would seem that your Jasmine / SpecRunner loader file is in a different directory than your require.js loader (main.js by default). You will need to configure require.js to use a different base path by doing the following:

jQuery(function(){
require.config(
{
  baseUrl: '/public'
});

var include = ['js/widget.js',
               'js/delta_widget.js',
               'js/inbox.js',
               'js/time_widget.js',
               'js/high_stock_widget.js',
               'js/daily_summary_widget.js'];

require(include,function()
{
  $.getScript('/js/app.js');
});

      

You need to configure the above baseUrl property to point to the correct URL / Path. For example, if your Jasmine SpecRunner is in:

basic - main.js - js - widget.js - app.js - Liza - Jasmine --- SpecRunner.html



then you need to configure

baseUrl: "../../"

      

Hope it helps.

+2


source







All Articles