To execute javascript unit and integration tests with ember.js follow the steps below:
install the qunit plugin
npm install karma-qunit --save-dev
install the ember preprocessor plugin
npm install karma-ember-preprocessor --save-dev
generate a configuration file for karma
karma init
note -the above will walk you through the basic setup. An example configuration file that works with ember.js/qunit and phantomjs is below
module.exports = function(config) {
config.set({
basePath: 'js',
files: [
'vendor/jquery/jquery.min.js',
'vendor/handlebars/handlebars.js',
'vendor/ember/ember.js',
'app.js',
'tests/*.js',
'templates/*.handlebars'
],
browsers: ['PhantomJS'],
singleRun: true,
autoWatch: false,
frameworks: ['qunit'],
plugins: [
'karma-qunit',
'karma-ember-preprocessor',
'karma-phantomjs-launcher'
],
preprocessors: {
'**/*.handlebars': 'ember'
}
});
};
Note - the files
section above should include all dependencies, ie- jQuery/handlebars/ember.js along with the js and handlebars files required to deploy and run your production ember.js application
add a simple qunit test
test('one should equal one', function() {
equal(1, 1, 'error: one did not equal one');
});
run the tests with karma from the command line
karma start
A simple unit / integration tested example app showing karma / qunit / ember in action can be found here