Reputation: 127
I have been tasked with setting up unit tests for a legacy AngularJS application (none currently exist, so I am setting it all up). However, I have been running into some issues getting my initial test to run. I've been peeling the onion of errors for a while now, but I'm stuck on this current one.
When I run the command 'karma start', it throws the following error (It must be noted that I am only getting this error while trying to run my unit test, it does not occur when I build the application to run locally):
"message": "Uncaught TypeError: Cannot read property 'plugins' of undefined at Web/js/plugins/flot/curvedLines.js:308:12
And that line is the following code: $.plot.plugins.push(
I've read multiple github and stackoverflow links, and I've followed their advice, but I am still running into the issue. I have tried putting the script tags near the top of my index.html file, and my karma.conf.js file is definitely including the files for the flot plugin through the line:
'Web/js/plugins/**/*.js',
//the full path for the plugin is 'Web\js\plugins\flot'
However, I did notice that there is a 'jquery.flot.js' file. Will the line in my karma conf above include that jquery file? As an experiment, I also included the following line in my karma.conf.js file:
'Web/js/plugins/flot/jquery.flot.js'
However, when doing so, Karma throws another error. This time, saying that I am not loading my main app module, with the exact error being:
Uncaught Error: [$injector:nomod] Module 'app' is not available! You either misspelled the module name or forgot to load it.
However, I am loading my application at the very top of my unit test file in a before each statement, so I don't know why this would be throwing an error. Additionally, my app is not just called 'app', it has a different name, and I have that differently named module included properly.
So right now, I am a bit lost. Am I on the right track with including that jquery.flot.js file explicitly in my karma.conf.js file? Or is that the wrong approach and I should only have the 'Web/js/plugins/**/*.js'
line? If so, where should I look next?
Thanks in advance.
Upvotes: 1
Views: 1578
Reputation: 127
Not sure if this will help anyone, but I figured out my issue.
Apparently, there were some dead plugins that Karma was picking up thanks to my over-reaching statement in the files section. These plugins had dependencies on other packages not included in the project, which threw errors. Excluding these files in karma.conf.js fixed my problem.
Upvotes: 1