0

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?

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

Nephilim700
  • 73
  • 1
  • 10

1 Answers1

0

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

uchiya
  • 21
  • 5
  • Thanks for the response. I went through this link before posting but I don't want to run jasmine through browser. If I run through browser I am getting output as all my tests were passing. But I want to get the output through `npm` command or in this case `jasmine-node`. In this case I am getting `define is not defined` error. – Nephilim700 Jan 17 '19 at 06:26
  • Actually I am aiming for complete console output so anything related to `SpecRunner.html` won't help my case. – Nephilim700 Jan 17 '19 at 06:28