AngularJS - Karma (e2e) : Executed 0 of 0 ERROR - angularjs

I am experiencing a problem which I could not solve for some time, and getting very frustrating since I don't have an idea what I am doing wrong in it. :) Any help is much appreciated. I am using requirejs in my applications as well. This is basically what I am trying to build; https://github.com/Cengizism/base
When I try to start my e2e test I get this on my console;
INFO [karma]: Karma v0.10.0 server started at http://localhost:8080/_karma_/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 28.0.1500 (Mac OS X 10.8.4)]: Connected on socket id n-0AVRliCogs2nWBfgDz
Chrome 28.0.1500 (Mac OS X 10.8.4): Executed 0 of 0 ERROR (0.208 secs / 0 secs)
My configuration file looks like this;
module.exports = function(karma) {
'use strict';
karma.set({
frameworks: ['jasmine', 'ng-scenario'],
files: [
'app/vendors/angular-scenario/angular-scenario.js',
'test/e2e/*.js'
],
basePath: '',
exclude: [],
reporters: ['progress'],
port: 8080,
runnerPort: 9100,
colors: true,
logLevel: karma.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
captureTimeout: 5000,
singleRun: false,
proxies: {
'/': 'http://localhost:9000/'
},
urlRoot: '/_karma_/',
plugins: [
'karma-jasmine',
'karma-ng-scenario',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-phantomjs-launcher'
]
});
};
and finally the spec file;
describe('Simple E2e Test', function()
{
it('Should open the front page and check', function()
{
browser().navigateTo('/#/partial1');
sleep(1);
expect(element('#test').html()).toEqual('Hi testUser1');
});
});

Maybe this could help you:
To fix it, the following line should be included in karma.conf.js
exclude: ['app/lib/angular/angular-scenario.js'],
Source : https://github.com/angular/angular-phonecat/issues/71

I'm not exactly clear on this either, but after running into this issue I removed the file angular-scenario from loading and was able to get the tests to run. I believe the problem is the difference between unit testing and e2e testing configuration.

I had this same error, and it went away once I started adding some tests. Is it possible the error just means there aren't any tests present?

It could be due to the relative paths you add in files [] which may be wrong.
I had the same error, and after it works fine !

In my case, the module format was wrong in a shim file that was only used by karma. I changed the format to 'register' to support SystemJS modules, per the documentation found here.
System.config({
packages: {
'base/dist/client': {
warnings: true,
defaultExtension: 'js',
format: 'register',
map: { }
}
}
});
This is what the TS output looked like. I have to assume that these tests were wrapped as system modules, so they were not loading properly. In other words, the error resulted from no tests running.
System.register(['angular2/testing', "./data-pipe"], function(exports_1) {
var testing_1, data_pipe_1;
return {
setters:[
function (testing_1_1) {
testing_1 = testing_1_1;
}
]
// yada, yada, yada..
}
}
});

Related

Angular.js injector error doesn't give any hints about missing dependencies in Karma test

I'm trying to create few simple tests for my Angular.JS app, but unfortunately, I can't resolve missing dependencies due to very short output from Angular / Karma (?)
My Karma config looks as follows:
module.exports = function (config) {
config.set({
basePath: '',
singleRun: true,
autoWatch: false,
frameworks: ['jasmine'],
browsers: ['PhantomJS'],
preprocessors: {
'./src/app/myApp.app.js': ['babel']
},
files: [
'./node_modules/angular/angular.js',
'./node_modules/angular-mocks/angular-mocks.js',
'./src/app/myApp.app.js',
'./test.js'
],
plugins: [
'karma-mocha-reporter',
'karma-jasmine',
'karma-babel-preprocessor',
'karma-phantomjs-launcher'
],
babelPreprocessor: {
options: {
presets: ['env'],
sourceMap: 'inline'
},
sourceFileName: function (file) {
return file.originalPath;
}
},
reporters: ['mocha']
});
}
What I'm doing here is basically including angular, angular-mocks, entry module for my app and one file with tests. Of course, some dependencies are missing now, but I'd like to add only required ones (and learn about missing steps after karma start).
Unfortunately, after running karma start I can only see that test has failed, and that's all - nothing more (for example, at runtime you can see 'rich' error message in browser's console, based on which you can include missing dependencies). Take a look at this error:
x it should do something funny
PhantomJS 2.1.1 (Mac OS X 0.0.0)
node_modules/angular/angular.js:4693:53
forEach#node_modules/angular/angular.js:325:24
loadModules#node_modules/angular/angular.js:4653:12
createInjector#node_modules/angular/angular.js:4575:30
WorkFn#node_modules/angular-mocks/angular-mocks.js:3120:60
And that's all. If I include minified version of Angular, I see a browser-like error message, based on which I can add required dependencies. With non-minified version, it's working like I've described. So my question is - how can I make error messages rich in karma tests?

Karma Not Running - cannot find module gulp

I'm trying to set up karma tests with Jasmine on my Angular project.
I can't get basic test
`it("dummy", function() {
expect(true).toBe(true);`
to run, and I'm getting the error:
PhantomJS 1.9.8 (Linux 0.0.0) ERROR
Error: Cannot find module 'gulp'
This is my gulp test task:
gulp.task('test', function(coverage) {
gulp.src('dummy')
.pipe(karma({
configFile: 'karma.conf.js',
action: 'run'
}))
.on('error', function(err) {
// Make sure failed tests cause gulp to exit non-zero
throw err;
});
});
And this is my karma conf file:
module.exports = function(config) {
config.set({
// base path, that will be used to resolve files and exclude
basePath: '',
// testing framework to use (jasmine/mocha/qunit/...)
frameworks: ['browserify', 'jasmine'],
plugins : [
'karma-browserify',
'karma-jasmine',
'karma-phantomjs-launcher'
],
preprocessors: {
'src/app/**/*.spec.js': [ 'browserify' ],
'src/components/**/*.spec.js': [ 'browserify' ],
'src/services/**/*.spec.js': [ 'browserify' ]
},
// list of files / patterns to load in the browser
files: [
'bower_components/jquery/dist/jquery.js',
'bower_components/angular/angular.js',
'bower_components/angular-cookies/angular-cookies.js',
'bower_components/angular-mocks/angular-mocks.js',
'bower_components/angular-resource/angular-resource.js',
'bower_components/**/*.js',
'src/**/*.spec.js'
],
// list of files / patterns to exclude
exclude: [],
// web server port
port: 8080,
// level of logging
// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG
logLevel: config.LOG_INFO,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// Start these browsers, currently available:
// - Chrome
// - ChromeCanary
// - Firefox
// - Opera
// - Safari (only Mac)
// - PhantomJS
// - IE (only Windows)
browsers: ['PhantomJS'],
// Continuous Integration mode
// if true, it capture browsers, run tests and exit
singleRun: false
});
};
Please help me stackoverflow you're my only hope!
The most common question: did you install gulp correctly?
npm install gulp
Also check which files you are loading into the files property in karma.conf.js. There should be only your 3rd party libraries js files, your custom js files and your test files.
There's also a chance that your gulp task is not correct but since I often use grunt, I can't really help in that part :P

Angular E2E with Karma: unreliable event handling

I'm confronted with a strange error when executing my E2E tests.
A broadcasted event is not consumed by one of my directives anymore and therefore a particular view is not rendered correctly.
This does not occur only when I run the test alone.
And, this does not occur either when I run the test for the first time (singleRun=true) or the first run in debug mode.
The implemented event logic itself works fine.
What can cause this strange behavior?
My set up:
Karma version: 0.10.10
Angular version: 1.3.0
My Karma Config:
module.exports = function(config) {
config.set({
basePath: '',
files: [
'test/e2e/*.js'
],
singleRun: true,
frameworks: ['ng-scenario', 'jasmine-jquery', 'jasmine'],
browsers: ['Chrome'],
plugins: [
'karma-chrome-launcher',
'karma-jasmine-jquery',
'karma-jasmine',
'karma-junit-reporter',
'karma-ng-scenario'
],
junitReporter: {
outputFile: 'test-result.xml'
},
urlRoot: '/_karma_/',
proxies: {
'/': 'http://localhost:' + (process.env.PORT ? process.env.PORT : '8080') + "/"
},
});
};
Any hints are very much appreciated!
Thanks, Sebastian
As Thomas pointed out: Protractor is more appropriate for angular acceptance/E2E tests (https://docs.angularjs.org/guide/e2e-testing).
When using Protractor as test runner, the issue does not occur (at least not, when executing it only once [which was working fine with karma as well g]).
Thanks anyhow.

Understanding AngularJS testing

I seem to be unable to wrap my head around the concept of testing AngularJS applications.
I use PHPstorm as my IDE and have successfully installed node.js aswell as karma through node.
I have then created a karma.config file:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['jasmine'],
files: [
'js/angular.js',
'js/va.angular.js',
'test/**/**/*Spec.js'
],
exclude: [
],
reporters: ['progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: ['C:/Program Files (x86)/Google/Chrome/Application/chrome.exe'],
captureTimeout: 60000,
singleRun: false
});
};
I have also created a test file:
// mainSpec.js
describe('controllers', function(){
beforeEach(angular.module('va'));
it('should friggin test something', inject(function() {
var x = 5;
expect(x.toBe(5));
}));
});
However, as i try to run my test, it fails due to:
TypeError: Object #<Object> has no method 'apply'
TypeError: Object 5 has no method 'toBe'
Now i have 2 questions:
What am i doing wrong here?
Where does the karma stuff get the jasmine stuff from? To me it looks like it can't get it.
Make sure you're including the angular-mocks.js module in your list of files to load.
When you specify frameworks: ['jasmine'] in the karma config, it includes jasmine so there's no need to include it yourself.
As for your error,
expect(x.toBe(5))
should be:
expect(x).toBe(5)

PhantomJS and Karma, Selector [ng\:model="query.name"] did not match any elements

When executing a karma runner using the PhantomJS browser the following error is produced:
*Selector [ng\:model="query.name"] did not match any elements*.
When executing with Chrome everything is working as expected.
Here's the line that should be matched:
`<input size='' style='width:3em;' ng-model="query.name" ng-change=changeQuery() ng-focus=focus($index) ng-blur=loseFocus($index)>`
karma.conf:
module.exports = function(config) {
config.set({
basePath: '../..',
frameworks: ['ng-scenario'],
plugins : [
'karma-ng-scenario',
'karma-chrome-launcher',
'karma-phantomjs-launcher',
'karma-junit-reporter'
],
files: [
'test/webapp/app/e2e/*.js'
],
exclude: [
],
proxies : {
'/': 'http://localhost:19880'
},
reporters: ['progress', 'junit'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: false,
browsers: [ 'Chrome', 'PhantomJS'],
captureTimeout: 60000,
singleRun: false
});
NodeJS version: v0.10.17
Karma version: 0.10.2
PhantomJS version: 1.9
The root cause of the failure was that the PhantomJS is built with an old version of JavaScript that is missing the "bind" implementation (Why PhantomJS doesn't have Function.prototype.bind)
The controller logic was using currying, with the bind method, and thus caused the page render incorrectly. I found this out when exporting a rendered page with the phantomJS browser.
I removed all the bind method calls from the controller code and End2end test(s) are now passing as as expected.
I apologize that from the information that I have provided for the issue, it is impossible to deduct the problem cause.

Resources