Question

I'm writing a module for Angular JS and I'd like to ensure that it works with several versions of Angular. Is there a way to tell Karma to run the test suite with several different dependencies (e.g. first all the tests with Angular 1.2.1, then 1.2.2 and so on)?

Was it helpful?

Solution

I assume you run your test with Grunt, so you can

1) define your grunt different entries for different angular versions

karma: {
  ang11: {
    configFile: './test/karma-ang1.1.conf.js',
    autoWatch: false,
    singleRun: true
  },
  ang12: {
    configFile: './test/karma-ang1.2.conf.js',
    autoWatch: false,
    singleRun: true
  }
}

2) in each file you refers different angular version and the test suits

3) you configure a task to run sequently your karma config files

OTHER TIPS

With the help of another question I used grunt-karma's overrides to reuse my karma config file. So my Gruntfile.js has this:

meta: {
  jsFiles: [
    'app/scripts/**/*.js',
    'test/spec/**/*.js'
  ]
},
karma: {
  options: {
    configFile: 'karma.conf.js',
    singleRun: true
  },
  angular13: {
    files: [{
      src: [
        'test/ref/angular-v1.3.js',
        '<%= meta.jsFiles %>'
      ]}
    ]
  },
  angular14: {
    files: [{
      src: [
        'test/ref/angular-v1.4.js',
        '<%= meta.jsFiles %>'
      ]}
    ]
  }

Note the src: inside files:. Without it you'll get a "Cannot use 'in' operator ..." error and has to do with how Grunt handles files.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top