# Category: karma-runner

## Karma jasmine test angular 5 cannot call Promise

I am new to karma jasmine test and I am struggling with a test that always gives this error when I launch the test: Error: Cannot call Promise.then from within a sync test. I am using angular 5. Here is my test code: fdescribe(‘CommentComponent’, () => { let component: CommentComponent; let fixture: ComponentFixture<CommentComponent>; let commentService: CommentService; const stationId = 900; let station: Station; let comment: Comment; beforeEach(fakeAsync(() => { station = new Station(); station.id = […]

## How to run command-line process in karma

I am writing an integration test (not a unit test) for my AngularJS / CouchDB application using Karma. I realize that in unit tests mocking the database is important. I am deliberately NOT mocking the database since this is an integration test. I explicitly DO want to interact with the database. The following works when I run code in protractor exec(“my command that loads data into the database”). In karma exec() is not available. How […]

## Testing Angular Service with Jasmine: Failed to instantiate module app

I am trying to create a Simple Unit Test using Jasmine for an Angular Service. But when I am running the Test via Karma, I am getting the following error: Failed to instantiate module app And I don’t know why I am getting this error. I Googled and tried to apply the below solutions. But none worked. I tried changing the sequence of files in the karma.conf.js. I tried writing the Unit test in different […]

## Error on setting up karma, jasmine for Angular1.x application with requirejs configuration

Our Angular 1.x application uses requirejs For setting up karma – jasmine we have used below karma conf file: module.exports = function(config) { config.set({ basePath: ”, frameworks: [‘jasmine’], files: [ ‘node_modules/angular/angular.js’, ‘node_modules/angular-mocks/angular-mocks.js’, ‘src/test/**/*.spec.js’, ‘src/**/*.js’ ], exclude: [ ], preprocessors: { ‘src/main/webapp/js/**/*.js’ }, coverageReporter: { type: ‘html’, dir: ‘coverage’ }, plugins: [ ‘karma-jasmine’, ‘karma-chrome-launcher’, ‘karma-coverage’ ] reporters: [‘progress’, ‘coverage’], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: [‘Chrome’], singleRun: false, concurrency: Infinity }) } But […]

Added a timeout to reload the page in the controller after a certain amount of time, however now all the karma tests are failing. Controller code: function mainController($route,$scope, $timeout) {$scope.toggle = false; $scope.value = function() { if($scope.value) { $scope.toggle = true; } else {$scope.toggle = false; } } $timeout($route.reload, 10000); } Tests: describe(‘mainController:’, function() { describe(‘test mainController’, function () { beforeEach(inject(function ($injector) { this.$scope = $injector.get(‘$rootScope’).$new(); this.$route = $injector.get(‘$route’); this.$timeout =$injector.get(‘$timeout’); […] ## What unit testing is best for an application which is running on Angular 1.5 among Karma, Protractor or Jasmine or others? I have a AngularJS 1.5 application with 5-6 modules with lots relying on directives and stuff. How do i figure out which testing is better for our application to actually built a test harness over it? I have been through many types, some are runners and e2e etc., Karma, Protractor, Jasmine are the most familiar ones but how would we test the application; is it whole application one at a time like other automation tools? […] ## Karma: Error: [$injector:nomod] Module ‘app’ is not available

I am new to Angular World and very beginner at Karma. I am receiving the following error when I am trying to run the Karma-Jasmine Unit test. { “message”: “An error was thrown in afterAllnUncaught Error: [$injector:nomod] Module ‘app’ is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.nhttp://errors.angularjs.org/1.6.9/$injector/nomod?p0=app”, “str”: “An error was thrown in afterAllnUncaught Error: […]

## How to load a angularjs controller’s templateUrl into a jasmine test?

I am new to angular and jasmine, so this is probably a simple one. However, I am having trouble accessing the HTML template from the jasmine test. I create the controller with a beforeEach. beforeEach(angular.mock.module(‘yeomanApp’)); beforeEach(angular.mock.module(‘yeomanApp.services’)); beforeEach(inject(function ($controller,$rootScope, $routeParams, _$httpBackend_, $window, ) { scope =$rootScope.$new(); routeParams =$routeParams; httpBackend = _$httpBackend_; window =$window; SampleCtrl = $controller (‘SampleCtrl’, {$scope: scope, $routeParams: routeParams,$http: httpBackend, \$window: window }); })); However, I can not […]