Unfortunately no. Karma v0.12.31 is incompatible with the latest stable version of Nodejs (v0.12.0). On the Karma website, under Installation > Installing Node.js there is a disclaimer: Note: Karma works on the two latest stable versions. That is 0.8.x and 0.10.x at this point. Even though the latest stable version...

I couldn't find much in the way of any API documentation on Jasmin, but the functions you mention seem to be part of AngularJS, to which the only documentation I could find that referenced either of those functions (with regards to Jasmin) was this site which states the following: browser().window().href()...

While I'm taking a different approach** to using Karma with Babel in my project, I suspect you're having the same problem I was: the Babel polyfill is not being loaded, and so you're not getting the functionality it supports (including the custom regenerator runtime that Babel uses to make generators...

It looks to me like the $scope.company is the same as the company that is injected into your controller. So you need only to set an Address on the company that you are injecting into your mock, like so: beforeEach(inject(function ($rootScope, $controller ) { scope = $rootScope.$new(); createController = function()...

The code you are trying to test is run when the controller is instantiated, which happens before you've tested anything. You need to re-instantiate the controller in the it block it('does else', inject(function($rootScope) { $rootScope.serviceNumber = 'not m1'; theController = $controller( ... instantiate again ) expect(... })); Better would be...

Answer : CORS. It seems all this was because the API server didn't allow the test server to to do cross-origin requests. The django app (API) uses django-cors-headers to generate CORS headers. What I hadn't realized is that there's a distinction on host based on ports : CORS_ORIGIN_WHITELIST = (...

The problem is similar to this issue. However, it looks like Chrome needs to be in the foreground (maybe a recent change?)... I don't see the problem in Firefox. So, the solution is to use Firefox instead. However, if Chrome needs to be used specifically, you can read another question...

As is often the case with these kind of errors, the fix is pretty obvious when you see it! Basically there are two functions in controllersSpec.js, one for a list of phones and one for an individual phone's details. The phone list tests were working fine because they had beforeEach(module("phonecatApp"));...

And I can't understand why I am getting the following error: you defined fileLoader.getFile("test") .then(function(res){ so getFile() should return a promise which could be resolved, but you return a simple array with two objects inside test.getFile = function(name) { return [ { "id": 0, "name": "Test", "imgName": "Test.png" },...

Earlier I had been getting the error: Mismatched anonymous define() module: ... So I had changed the define function call from define(['angular'], function(angular) { .... }); to define('helloTests', ['angular'], function(angular) { .... }); That got rid of the error details, but didn't fix anything. It turns out it also wasn't...

The coverage plugin preprocess your source code and produces a version of it suitable to track the coverage - that's why all those lines have counters (random-variable++) everywhere in it. Moving the files in another directory not mapped by the coverage plugin leaves your source code as is. If you...

If you would be happy with opening an HTML report that Karma generated for you, then take a look at karma-html-reporter. Just add it to the reporters list in your Karma configuration: { // much more before this reporters: ['progress', 'html'], // the default configuration htmlReporter: { outputDir: 'karma_html', //...

The issue turned out to be that I was not loading in the appropriate bower_components into the karma.conf.js. Changing to the un-minified version of angular allowed me to see the more descriptive errors which helped me solve this.

The problem is that you are not injecting the required service into the controller. It is calling getGeneralSettings.get() but getGeneralSettings is never injected, so this should lead into an error. You only provided $rootScope. $scope, GeneralSettingsService, getGeneralSettings are missing. You must provide your own mock object that simply responds with...

Looks like you are running tests in browser which doesn't support Function.prototype.bind. Babel needs this function. You can fix is by karma-phantomjs-shim, or try a new version of browser. Since version 2.0, PhantomJS has this function....

Ok, I finally found the bug report: https://github.com/karma-runner/karma-jasmine/issues/73 Apparently they have changed from using ddescribe and iit to using fdescribe and fit for 'focused' testing....

When you fire karma up, what karma does is: It does some pre-process job It creates a webpage where your web assets are loaded (css, js, etc...) It creates a webserver to serve your assets The webserver needs to know where you have your own assets and if you want...

The solution for this problem was that I had a couple of installed node_modules within my users home folder. After deinstalling these modules and the locally installed ones via npm, I made a clean reinstall via npm link. This solved the problem for me!

grunt serve uses watch task to watch for file changes. By default watch configuration for tests only includes JS files inside "test" folder. To run tests every time JS files inside "scripts" folder are changed you need to add those files to watch:jsTest task configuration inside your Gruntfile.js. It should...

Perhaps I am missing something, but jasmine.createSpyObj makes new spies with no implementations whatsoever attached to them. What you want instead is a spy which calls through to the original function, since your promise chain assumes patientCache.saveCurrentPatient exists. Try setting up your spies with the spyOn(obj, 'patientCache').and.callThrough() syntax. Note that...

Any given promise can only be used to return one outcome (be it resolved or rejected), so trying to reject a promise subsequent to resolving it will not work. The simplest way to test your method would be to split your test into two, with one for each outcome: it('should...

You should look into ng-html2js-preprocessor: https://github.com/karma-runner/karma-ng-html2js-preprocessor It will batch up all your templates into a template cache module (that uses $templateCache under the hood) that you can use: describe('SOMETHING', function() { beforeEach(module('templates')); ...

You would need to include angular.js as well, then only angular.mocks will work else window.angular will be undefined. files: [ 'dom_munger.data.appjs', 'path/to/angular.js', //<-- include angularjs 'bower_components/angular-mocks/angular-mocks.js', 'tests/spec/*.js' ], ...

I remember having similar problem. Not sure if the problem is exactly the same, but I solved it copying the properties of lodash in a new object, which I then returned from the factory : function lodash($window) { var lodashLib = $window._; var _ = {}; delete( $window._ ); //...

You need to update the package.json file with the appropriate versions of the npm packages. Uninstall first by running sudo npm uninstall and then update the package.json. Run npm list to check the versions of the packages installed for your project. Try uninstalling the unmatched version package by providing the...

there are multiple things going on, let's check it one by one: at your test, you don't need do load all your modules, load just that module, that you want to test, your ctrl is in your MainModule, so use just beforeEach(module('MainModule')); every module should declare its dependencies, so your...

I think you may look into different solutions here, depending on how you want to manage your project. Solution n.1 Use AMD/RequireJS: do not load your modules all at once but just require them when you need. Sometimes it may not fit your needs tough making the project over complicated,...

Your controller's isCompleted method is wrong: your list is an array of objects, no strings: self.addTask = function() { self.listDisplay.push({task: self.taskTerm, completed: false}) }; If you set taskTerm as "hello", the object that is pushed into the array is not the string "hello", but an object like {task: "hello", completed:...

You can use a headless browser for unit testing. If you need a headless browser with karma/jasmine,you can use PhantomJS karma launcher . You can simply specify this when you run karma init , and it will ask you for a browser launcher in one of the steps of that...

I had this: grunt.registerTask("name_of_task", ["task_a", "task_b", "task_c"]); And "task_b" had to be executed after "task_a" was done. The problem is that "task_a" is asynchronous and returns right away, so I needed a way to give "task_a" a few seconds to execute. The solution: grunt.registerTask("name_of_task", ["task_a", "task_b:proxy", "task_c"]); grunt.registerTask("task_b:proxy", "task_b description",...

I figured it out through random trial and error. Apparently you have to use the magic word "base" in your path. proxies: { '/fake.png': '/base/spec/javascripts/fixtures/assets/fake.png' } now it works, but let's be honest, prepending "/base" just seems like nonsense....

It turned out that I had a path defined in my directive which was very hard to find, hence the error Error: Unexpected request: GET ../../../views/components/KonstruktStdFilterbox/KonstruktStdFilterbox.html angular.module('app').directive('directive', function(utilities) { return { restrict: 'E', //element templateUrl: '../../../views/components/KonstruktStdFilterbox/KonstruktStdFilterbox.html', scope: true, replace: true, .. And when I changed the templateUrl to this the...

configFile property is just a file name. So when you provide __dirname + '../Tests/karma.conf.js' it corresponds to the actual file location. You can actually do: configFile: path.join(__dirname, '../Tests/karma.conf.js') With fs.readFile you read a file and provide its contents to the karma runner. I am not sure why you are not...

I solve this problem upgrading the version of npm from 1.2.24 to 2.5.0 with the following steps: Navigate to C:\Program Files (x86)\nodejs or C:\Program Files\nodejs, depending on the version installed with cmd.exe. Run the installation without -g: npm install npm. Then run the Karma installation command: npm install karma. I...

The cancelMeeting function is not added to the scope until the controller is created. So I think you just need to reverse the lines in your test code: it('the meeting type should be equal to an object', function () { var controller = new createController(); spyOn(scope, 'cancelMeeting'); }); ...

Since your controller doesn't use $scope, you shouldn't be injecting it and using it in your tests. Instead you should be checking for title on your controller: describe('Controller: Login', function () { beforeEach(module('ttn')); var controller; beforeEach(inject(function ($controller) { controller = $controller('Login', {}); })); it('should define a title', function () {...

The documentations says Capturing browsers on your own can be a tedious and time consuming task, so Karma can automate this for you. Simply add the browsers you would like to capture into the configuration file: browsers: ['Chrome'] Note the name of the property: it's browsers, not browser....

You could just pass the locations to the spy as resolved promise value with $q.when: lstStub.withArgs('location').returns($q.when(locations)); and it should just work fine. The reason why it is not working in your case is because you are creating a promise from deferred object and never resolving it with appropriate value. when(value);...

I believe in case of your unit test, Angular is loading jqLite instead of jQuery, which does not have add function. Either use one of the jqlite compatible function described here https://code.angularjs.org/1.2.9/docs/api/angular.element Or include jQuery too in your tests, in karma config....

Short Answer I believe your issue is that you are using angular.module instead of either just module or angular.mock.module. Long Answer The Angular mock library creates a mock module and inject function. It must do this as the non-mocked version of module and inject must still be able to function...

I came across a solution to the problem. I ended up changing my test-main.js file above the require.config section to this: // Karma RequireJS configuration var tests = []; for (var file in window.__karma__.files) { if (/Spec\.js$/.test(file)) { tests.push(file); } } If I simply changed TEST_REGEXP to /Spec\.js$/ I ended...

I haven't used grunt-karma before, but the easiest option is probably to configure your watch task, so that it runs it's tasks at startup. This can be done via options.atBegin. So if you take the example from the grunt-karma documentation, you would write: watch: { karma: { files: ['app/js/**/*.js', 'test/browser/**/*.js'],...

I still couldn't let this go, so had to play with it more. I found my error. This line: menu = angular.element('<menu></menu>'); was being used wrong. It needed to be menu = angular.element('menu');. Angular.element is not meant to be used with the full tag, but with classes, ID's, or the...

You are right about karma not being a good fit for testing server side code. It is going to run everything in the context of a browser, which is causing the issues you are seeing. If you wanted to develop a module for the server and the client you could...

You can use gulp.watch to compile the typescript files on on save. That way when you run the tests the typescript is already compiled. The gulp-tsc module should have a guide for setting up incremental compiling.

I was having this issue with an older version of node, too. If you don't want to have to hard-code this environment variable, updating your version of node will solve the problem. Just do the following (OSX instructions): npm uninstall -g phantomjs npm cache clean -f brew upgrade nodejs rm...

This is indeed strange, and is perhaps something the angular team didn't consider. When a promise is rejected by throwing (as you're doing), the angular $exceptionHandler service is called with the thrown exception. By default, this service just logs the exception in the browser console. But when using ngMocks, this...

The issue is that when you get the module in your spec file test setup, you are actually creating it by specifying the second argument, so it just clean up everything that is registered under that module. Change: beforeEach(module('myApp.views.view1',[])); to beforeEach(module('myApp.views.view1')); and also when you instantiate the controller using $controller...

The reason you having problems is with $httpBackend.verifyNoOutstandingExpectation(); is due to your last test it("should log in when valid credentials are given", function () { $httpBackend.expectGET("users/login"); webservice.withCredentials("sam", "password"); }); having unsatisfied requests which you can see in this jsfiddle Error: Unsatisfied requests: GET users/login If you comment out $httpBackend.verifyNoOutstandingExpectation() your...

See if this works, it("buttonDisable should equal to false", function() { scope.save(); /* However here you have to flush any http request or $timeout using $httpBackend.flush() and $timeout.flush() respectively for success function to get called. */ expect(scope.buttonDisable).toEqual(false); //assertion }); ...

Instead of setting string green set it on the scope bound when the directive element is compiled in your startup of the test. Otherwise it will look for the value of scope property with the name green on the bound scope, and which of course is not defined in your...

I ended up figuring out the issue. TestUtils.Simulate.keyDown(input, {key : "a"}); This line sends an event to the correct DOM node, but the event data doesn't actually contain a keyCode, which is what the code is looking for. Why the official documentation specifically says you should use key is beyond...

Normally, at runtime, angular creates a scope and injects it into the controller function to instantiate it. In your unit test, you instead want to create the scope by yourself and pass it to the controller function, in order to be able to see if it indeed has 3 phones...

The error : Error: Unexpected request: GET http://ip_address/plans/postpaid No more request expected Means that there is actually no call made to that url, start by double checking the url you'r testing. In test, for promise to be executed you have to call $rootScope.$digest(); (to avoid asynchronous testing, in the same...

Issue is solved though not sure if it's the best way to solve it. Since we were trying to use "traceur" and "browserify" in a chained pre-processing we figured that for some reasons, they aren't really getting executed in a chain. Both of these processed the files (matching the path)...

After opening the debug page you could see that angular was telling you that it was missing the reflect-metadata package. So I added a manual import statement, for it in app/todo/todo.js which solved the issue: import Reflect from 'reflect-metadata' import {ComponentAnnotation as Component, ViewAnnotation as View} from 'angular2/angular2'; import List...

Turns out this was a blunder from my side. I forgot that when Travis CI initialize the job, it always installs the latest npm modules. I reinstalled the npm modules locally and got the same behaviour on both ends. Hope this will help someone else with the same issue :)

I went out on a limb in the comments, and after a little digging I believe that I am right. The "_" is being stripped from your service name in test by the mock injector. Specifically, read the section Resolving References (Underscore Wrapping): To help with this, the injected parameters...

If you are only running a single instance of node, you'll have to uninstall version 12 and install an earlier version that is compatible. If that's the case, you should probably look into a node version manager that works on Windows. Tools like nodist or nvm-windows let you install multiple...