Code Monkey home page Code Monkey logo

Comments (3)

cloudchen avatar cloudchen commented on August 27, 2024

As my understanding and guessing, you might explicitly load Backbone
library in some ways before require.config({}) call, for instance, loading
it via script tag, the easiest way.

But here you don't load Backbone as helper before generated
require.config({}) by this template.

Try load Backbone via helper as an attempting.

BTW, I found a defect of your module definition which directly access
Backbone from global context rather than module's dependencies list.
Should fix that problematic invoking.

On Friday, May 17, 2013, Stefan Vermaas wrote:

Hi,

I'm using this template to run my jasmine tests in the requireJS
framework. But while using this template I ran into an issue. I'm not
exactly sure or this has to do with the template, RequireJS or Jasmine, so
please say so if I'm in the wrong repo.

In my main.js file ( where the configuration for my RequireJS application
lives ) I've defined some dependencies for my application. I "globalise"
jQuery, Backbone and Underscore, so I don't need to call them for the
second time in my modules.

// main.js// Define the basic configurationrequire.config({
baseUrl: 'app/javascripts',
paths: {
jquery: 'vendor/jquery/jquery',
underscore: 'vendor/underscore-amd/underscore',
backbone: 'vendor/backbone-amd/backbone',
},
shim: {
'backbone': {
deps: ['jquery', 'underscore'],
exports: 'Backbone'
},
'underscore': {
exports: '_'
},
'jquery': {
exports: '$'
},
'app': {
deps: ['jquery', 'underscore', 'backbone' ]
}
}});
// Define the applicationrequire(['app'], function( app ) {
app.initialize();});

This allows me to use jQuery, Backbone and Underscore in my separate
modules, like this:

define([], function() {
var Model = Backbone.Model.extend({});
return Model;});

But when I try this template for testing with Jasmine. I run into an
error. It tells me that Backbone isn't defined yet. But if I do include
Backbone in my module, the tests start working again.

// base_view.js with Backbone etc defineddefine([
'jquery',
'underscore',
'backbone'], function( $, _, Backbone ) {});

So what am I doing wrong? I can't figure it out..


Reply to this email directly or view it on GitHubhttps://github.com//issues/25
.

from grunt-template-jasmine-requirejs.

stefanvermaas avatar stefanvermaas commented on August 27, 2024

So what you're basically saying is defining a module like this ( see example below ) and load Backbone etc in every module. Correct?

// base_view.js with Backbone etc defined
define([
    'jquery',
    'underscore',
    'backbone'
], function( $, _, Backbone ) {
  // Define the baseModel
  var baseModel = Backbone.Model.extend();
  return baseModel;
});

Because on this way, the tests will succeed. I thought it was OK to get the Backbone object grom the global context, but I guess it isn't?

from grunt-template-jasmine-requirejs.

jsoverson avatar jsoverson commented on August 27, 2024

@stefanvermaas how are you loading backbone in your grunt config? If you don't pre-load it explicitly then it won't be loaded at all until you call it as a dependency (which is what your example seems to show)

Do you ever need it as an AMD dependency? If not, then you can load it in the vendor definition so that it gets loaded separately.

from grunt-template-jasmine-requirejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.