How to activate debugInfoEnabled only for unit tests?

In my angularjs 1.3 application, I disabled debugging information to improve performance:

$compileProvider.debugInfoEnabled(false);

But when I run my Jasmine tests using Karma, I got an error with Scope isolation:

var isoScope = element.isolateScope();

I know this is completely normal,
but I'm looking for a way to reactivate debugging just for testing.
Can I do this programmatically?
Can I determine what is in the karma-unit.conf.js file?

+4
source share
3 answers

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

:

// configFileLocal.js
angular.module('myapp.config')
.constant('apiUrl', 'https://myapi.com/api')
.constant('debugInfoState', true);

Grunt:

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: '<%= yeoman.app %>/scripts/root/config.js',
  },
  dev: {
    src: './config-files/configFileLocal.js',
    dest: '<%= yeoman.app %>/scripts/root/config.js',
  },
  ...

, , :

angular.module('myapp')
.config(function ($compileProvider, debugInfoState) {
  $compileProvider.debugInfoEnabled(debugInfoState);
});

/app/scripts/root/config.js . index.html /app/scripts/root/config.js .

+2

wiherek , grun/gulp. Angular

beforeEach(function() {
    module('myApp', function (_$compileProvider_) {
        _$compileProvider_.debugInfoEnabled(true);
    });
});
+2

debugInfo, :

angular.reloadWithDebugInfo();

.

-2

All Articles