简体   繁体   中英

“define is not defined” - jasmine-node requirejs in Nodejs

I am trying to run jasmine tests on files that are using requirejs. I have a require.config.js file which provides all the configuration for the requirejs and I am passing to this command to run the jasmine test.

jasmine-node --runWithRequireJs --captureExceptions --requireJsSetup spec/require.config.js spec/modules/test.spec.js

My require.config.js looks like this -

var require = {
    baseUrl: "../app",
      urlArgs: 'cb=' + Math.random(),
      paths: {
        jquery: '../assets/js/libs/jquery-1.8.2',
        underscore: '../assets/js/libs/underscore-min',
        backbone: '../assets/js/libs/backbone-min',
        jasmine: '../spec/lib/jasmine',
        jasminehtml: '../spec/lib/jasmine-html',
        boot: '../spec/lib/boot',
        spec: '../spec/',
        handlebars : '../assets/js/libs/handlebars-1.0.0.beta.6',

        // plugins
        jqueryui : '../assets/js/plugins/jquery-ui',
        jqgrid : '../assets/js/plugins/jqGrid',
        jqgridlocale : '../assets/js/plugins/i18n/grid.locale-en',
        jqform : '../assets/js/plugins/jquery.form',
        jqfiledownload : '../assets/js/plugins/jquery.fileDownload',
        migrate: '../assets/js/plugins/jquery-migrate',
        text : '../assets/js/plugins/text'
      },
      shim: {
        'underscore': {
          exports: "_"
        },
        'backbone': {
          deps: ['underscore', 'jquery'],
          exports: 'Backbone'
        },
        'jasmine': {
          exports: 'jasmine'
        },
        'jasminehtml': {
          deps: ['jasmine'],
          exports: 'jasmine'
        },
        'boot': {
          deps: ['jasmine', 'jasminehtml'],
          exports: 'window.jasmineRequire'
        },
        'handlebars' : {
                exports : 'Handlebars'
        },
        'text' : {
            exports : 'text'
        },
        'jqueryui' : [ 'jquery' ],
        'jqgrid' : [ 'jquery' ],
        'jqgridlocale' : [ 'jquery' ],
        'jqform':['jquery'],
        'jqfiledownload':['jquery'],
        'migrate':['jquery']
      }};

And my test.spec.js file looks like this -

define(['modules/models/RouteModel','modules/models/RestWebService'], function(RouteModel,RestWebService){

describe("RouteModel :", function(){
    it("should create an test instance", function(){
        expect(RouteModel).not.toBe(null);
    });
});

After running the command I am getting in the console

ReferenceError: define is not defined at C:\Users\TestProject\spec\modules\test.spec.js:1:1

What can be the problem in this case? Is this a path configuration issue?

PS - I want complete console output of jasmine, not browser output in jasmine.

Error is pretty much straight forward you need to load requirejs before calling it's function. you can find more clear idea from below link: https://stackoverflow.com/a/29317859/1607130

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM