asicfr asicfr - 3 months ago 34
AngularJS Question

how to activate debugInfoEnabled only for Unit tests?

In my angularjs 1.3 app, i disabled debug info to increase performance :


But when i launch my Jasmine tests with Karma, i got error with isolateScope :

var isoScope = element.isolateScope();

I know that it is completely normal,

but i'm looking for a way to reactivate the debug just for testing.

Can i do it programmatically ?

Can i define that in the karma-unit.conf.js ?


My approach to this was to create a set of config files, the load specific files via grunt or gulp, depending on the task or environment variables.

example config:

// configFileLocal.js
.constant('apiUrl', '')
.constant('debugInfoState', true);

an excerpt from Gruntfile:

copy: {
  test: {
    src: (function () {
      var filename;
      if (process.env.REMOTE_TESTS) {
        filename = './config-files/configFileTestsRemote.js';
      } else {
        filename = './config-files/configFileTestsLocal.js';
      return filename;
    dest: '<%= %>/scripts/root/config.js',
  dev: {
    src: './config-files/configFileLocal.js',
    dest: '<%= %>/scripts/root/config.js',

then of course you need to load it in your app like this:

.config(function ($compileProvider, debugInfoState) {

so /app/scripts/root/config.js is overwritten every time. in index.html, the only file that is loaded is /app/scripts/root/config.js this task should be run before any concatenation tasks.