Getting "Mismatched anonymous define() module..." when I try running tests

Priyabrat Nanda

I am trying to configure my karma jasmine unit testing with requirejs. But each time i run it, i am getting the below error:

Chrome 34.0.1847 (Mac OS X 10.9.2) ERROR
Uncaught Error: Mismatched anonymous define() module: function (angular){

 describe('Unit: Testing RequireJS', function(){
  var ctrl;
  var scope;
  var rootScope;

  beforeEach(angular.mock.module('wsaApp'));

  beforeEach(angular.mock...<omitted>...ch

Below are differenr file: spec file:

define(['angular'], function(angular){

describe('Unit: Testing RequireJS', function(){
   var ctrl;
   var scope;
   var rootScope;

beforeEach(angular.mock.module('wsaApp'));

beforeEach(angular.mock.inject(function($rootScope){
    scope = $rootScope.$new();
    rootScope = $rootScope;
}));

});
});

main.js

require.config({

paths: {
    /* ABC order */
    'angular': 'vendor/angular/1.2.0/angular.min'
},
shim: {
    'angular': { exports: 'angular' },

    'app/controllers': { deps: ['angular'] }
}
});

test-main.js

// This creates an array of all the files that Karma finds with a suffix of
// Test.js (eg utilsTest.js) to be added to the Require JS config below
var tests = [],
file;
for (file in window.__karma__.files) {
if (window.__karma__.files.hasOwnProperty(file)) {
    if(/spec\.js$/.test(file)) {
        tests.push(file);
    }
}
}
requirejs.config({
baseUrl: '/base/public/javascripts/',  // Karma serves files from /base/<your-base-path>
    paths: {
        /* ABC order */
        'angular': 'vendor/angular/1.2.1/angular.min'

    },
    shim: {
        'angular': { exports: 'angular' },
        'app/controllers': { deps: ['angular'] },           
         },
deps: tests,  // add tests array to load our tests

callback: window.__karma__.start  // start tests once Require.js is done
});

karma.conf.js

//Karma configuration
module.exports = function (config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',

// Fix for "JASMINE is not supported anymore" warning
frameworks: ["jasmine", "requirejs"],

// list of files / patterns to load in the browser
files: [
    'vendor/angular/1.2.1/angular.js',
    'jquery-1.7.1.min.js',
    'test/spec/**/*.js',
    'test/test-main.js'
],

preprocessors: {
    'app/**/*.js': 'coverage'
},

// list of files to exclude
exclude: ['app/main.js'],

// test results reporter to use
// possible values: dots || progress || growl
reporters: ['progress', 'coverage'],

coverageReporter : {
    type: 'html',
    dir: 'coverage/'
},


// web server port
port: 9876,

// cli runner port
runnerPort: 9100,

// enable / disable colors in the output (reporters and logs)
colors: true,

// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,

// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,

// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['Chrome'],

browserNoActivityTimeout: 100000,
// If browser does not capture in given timeout [ms], kill it
captureTimeout: 20000,

// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: true
  });
 }

i have tried different options mentioned in other threads, but nothing seems to work.

Priyabrat Nanda

Finally i solved all the issues and was able to run the jasmine test successfully with requirejs configuration. I had top mention all the dependencies in the karma config and mark them as included: false exclusively so that they get loaded by requirejs through my test-config file.

files: [
    {pattern: 'vendor/angular/1.2.1/angular.js', included: false},
    {pattern: 'vendor/angular/1.2.1/angular-mocks.js', included: false},
    {pattern: 'vendor/angular/1.2.1/angular-*.js', included: false},
    {pattern: 'vendor/bootstrap/bootstrap-*.js', included: false},
    {pattern: 'jquery-1.7.1.min.js', included: false},
    {pattern: 'app/app.js', included: false},
    {pattern: 'app/**/*.js', included: false},
    {pattern: 'test/test-config.js', included: true}]

only the test-config is loaded through karma and all others to be included in the karma config but mark as false.

Also, i had to load the app.js in my spec file so that the modules and controllers get loaded:

define(['angular-mocks', 'jquery', 'app/app'], function(angularmocks, $, app){
describe.....
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Mismatched anonymous define() module IE8

From Dev

Mismatched anonymous define() module IE8

From Dev

NG-TABLE - mismatched anonymous define() module

From Dev

Getting "Mismatched anonymous define() module..." when I try running tests

From Dev

Uncaught Error: Mismatched anonymous define() module: function definition(name, global)

From Dev

mismatched anonymous define() module typescript with AMD and export module

From Dev

loading Ace causes Uncaught Error: Mismatched anonymous define() module:

From Dev

Uncaught Error: Mismatched anonymous define() module: function definition(name, global)

From Dev

Brunch, RequireJS, and ReactJS is giving me "Error: Mismatched anonymous define() module"

From Dev

Backbone.js and Require.js: Mismatched anonymous define() module: function (_, Backbone) {

From Dev

Getting "No tests were found" when running unittest

From Java

Why am I getting this error when running Scala 2.13 tests in IntelliJ, but not with Scala 2.12?

From Dev

Getting undefined when i try to access parameter

From Dev

Getting ReferenceError: fetch is not defined when running react native tests in mocha

From Dev

Why am i getting a nullpointerexception when I try to setAdapter?

From Dev

I'm getting this error when I try to delete a row

From Dev

Why am I getting NULL when I try to initiate a connection?

From Dev

I am getting following error when I try to add constraint

From Dev

Red5 - Getting an error when I try to connect to server

From Dev

Getting a NullPointerException when I try to write an object to a server in Java

From Dev

Getting import error when I try to compile with cx_freeze

From Dev

Getting Error $routeProvider not defined when i try to use ngRoute

From Dev

New to c++ getting an error when I try to compile

From Dev

Red5 - Getting an error when I try to connect to server

From Dev

I'm getting this error when try to update to php5

From Dev

Getting error parsing sys.version when try to run BioPython tests

From Dev

Scala Play Framework - getting "cannot enqueue after timer shutdown" error when running tests that involve Akka

From Dev

Why do I keep getting NoSuchMethodError on LocationAwareLogger when running Jetty?

From Dev

Why am I always getting warnings when running Boost code?

Related Related

  1. 1

    Mismatched anonymous define() module IE8

  2. 2

    Mismatched anonymous define() module IE8

  3. 3

    NG-TABLE - mismatched anonymous define() module

  4. 4

    Getting "Mismatched anonymous define() module..." when I try running tests

  5. 5

    Uncaught Error: Mismatched anonymous define() module: function definition(name, global)

  6. 6

    mismatched anonymous define() module typescript with AMD and export module

  7. 7

    loading Ace causes Uncaught Error: Mismatched anonymous define() module:

  8. 8

    Uncaught Error: Mismatched anonymous define() module: function definition(name, global)

  9. 9

    Brunch, RequireJS, and ReactJS is giving me "Error: Mismatched anonymous define() module"

  10. 10

    Backbone.js and Require.js: Mismatched anonymous define() module: function (_, Backbone) {

  11. 11

    Getting "No tests were found" when running unittest

  12. 12

    Why am I getting this error when running Scala 2.13 tests in IntelliJ, but not with Scala 2.12?

  13. 13

    Getting undefined when i try to access parameter

  14. 14

    Getting ReferenceError: fetch is not defined when running react native tests in mocha

  15. 15

    Why am i getting a nullpointerexception when I try to setAdapter?

  16. 16

    I'm getting this error when I try to delete a row

  17. 17

    Why am I getting NULL when I try to initiate a connection?

  18. 18

    I am getting following error when I try to add constraint

  19. 19

    Red5 - Getting an error when I try to connect to server

  20. 20

    Getting a NullPointerException when I try to write an object to a server in Java

  21. 21

    Getting import error when I try to compile with cx_freeze

  22. 22

    Getting Error $routeProvider not defined when i try to use ngRoute

  23. 23

    New to c++ getting an error when I try to compile

  24. 24

    Red5 - Getting an error when I try to connect to server

  25. 25

    I'm getting this error when try to update to php5

  26. 26

    Getting error parsing sys.version when try to run BioPython tests

  27. 27

    Scala Play Framework - getting "cannot enqueue after timer shutdown" error when running tests that involve Akka

  28. 28

    Why do I keep getting NoSuchMethodError on LocationAwareLogger when running Jetty?

  29. 29

    Why am I always getting warnings when running Boost code?

HotTag

Archive