Getting “Mismatched anonymous define() module…” when I try running tests

前端 未结 2 1435
囚心锁ツ
囚心锁ツ 2020-11-30 09:24

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条回答
  •  暖寄归人
    2020-11-30 09:49

    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.....
    }
    

提交回复
热议问题