Search Posts

Category: karma-runner

Is it sensible to prevent an angularJS app being bootstrapped when testing with karma-runner?

I have an angularJS 1.6 project written in TypeScript, the entry file contains a statement to boostrap my application: angular.bootstrap(document, [‘app’]); When it comes to unit testing my app (using KarmaJasmine), I currently have a single test for a service belonging to a separate module, that’s a dependency of my app module. I have not yet written any specs that load in my app module I have some log statements in a run block […]

TS2322 – Typescript compilation error with ng.IPromise

When using Angular 1.x in combination with Typescript, I’m facing some problems. Considering this code: get(id): ng.IPromise<Server.MyItem> { return this.$http.get(`${this.baseAddress}/${id}`).then(d =>; } It’s compiled by tsc, but I ‘m getting the following error: Type ‘IPromise<{}>’ is not assignable to type ‘IPromise’ I tried to use the more specific IHttpPromise, but it does not do the tricks.. Any idea? Source: AngularJS

Using plan with AngularJS + Karma + Mocha

Is there a way to assert that an error callback will be hit? Something like this: it(‘test genericArrayResponse’, function() { let self = this; this.plan(1) return Promise.resolve(myService.genericArrayResponse({zoom:’bar’})) .catch(function (err) { self.confirm() }) }); in other words, using Mocha, how can I assert that there will be a callback? Should I just do this: it(‘test genericArrayResponse’, done => { return Promise.resolve(myService.genericArrayResponse({zoom:’bar’})) .catch(function (err) { done(!err); // simple assertion that error is truthy }) }); Source: AngularJS

scope method in AngularJS directive is not a function, when unit testing

I have this Mocha test: ‘use strict’; /////////////////////////////////// describe(‘all admin page directives’, function () { let scope, $compile, element, tmp; //load angular module beforeEach(module(‘app’)); //load directive template beforeEach(module(‘templates’)); afterEach(function () { scope.$destroy(); }); describe(‘category’, function () { beforeEach(inject(function ($injector) { $compile = $injector.get(‘$compile’); var $rootScope = $injector.get(‘$rootScope’); scope = $rootScope.$new(); scope.rightSidebarData = {}; $compile(‘<create-category right-sidebar-data=”rightSidebarData”></create-category>’)(scope); return scope.$digest(); })); it(‘should do something’, function () { scope.updateModel(); // <<<<<< ERROR HERE }); }); }); here is my […]

stubbing `window.location.reload` for unit tests – "Some of your tests did a full page reload!"

I have this in a controller: $ = function(){ return RolesService.remove({ data: role }) .then(function (v) { if (!(v && v.cdtError)) { $window.location.reload(); } }); } $window is injected into the controller and then in my unit test: let $window = {location: {reload: sinon.spy()}}; module(function ($provide) { $provide.value(‘$window’, $window); $window.onbeforeunload = sinon.spy(); }); the above stub doesn’t seem to do anything, because I still get this error: Some of your tests did a full page […]

karma / selenium error – trying to access: http://:9876/?id=77115711

I ran karma start I am getting this: INFO [karma]: Karma v1.7.1 server started at INFO [launcher]: Launching browser selenium_chrome with concurrency 5 INFO [launcher]: Starting browser chrome via Remote WebDriver ERROR [karma]: {“message”:”[get(“http://:9876/?id=77115711”)] Error response status: 13, UnknownError – An unknown server-side error occurred while processing the command. Selenium error: unknown error: unhandled inspector error: {“code”:-32000,”message”:”Cannot navigate to invalid URL”}n (Session info: chrome=63.0.3239.84)n (Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The […]

Using Jasmine + Karma to test Angular JS app with ASP.Net MVC

My app is built with MVC and angular.js. There is angular service, myAppConfigService, that is rendered by layout.cshtml page. This is because the myAppConfigService includes some paths which have to be generated by MVC helper method. When I run karma, it show error that the myAppConfigService is not available. I understand this error is because the layout.cshtml is not run by karma. But how can I solve this isseu? Thanks. Chrome 58.0.3029 (Windows 7 […]

Jasmine – How to Spy and test an AngularJS asynchronus Service

I am trying to spy on an asynchronous service call, however so far not successful. Though the synchronus calls are able to Mock. commonService.getResource(ResourceConst).then(function (result) { $scope.resource =; }, function (error) { loggerService.log(error); }); Actual Get Resource Function function getResource(resourceURL) { var deferred = $q.defer(); var url = resourceURL + “.json”; $http.get(url).then(function (data) { deferred.resolve(data); }, function (error) { deferred.reject(error); }); return deferred.promise; } Even though I was able to spy on synchronus methods […]

Automate test in ionic-v1 with m-generator

I had developed accounting app it’s working perfectly but I would like to write automated test in ionic m-generator and karma with jasmine. I had added a lot of plugins to my projects if I execute my project I faced some errors. the errors are fixed through StackOverflow. The errors are: TypeError: undefined is not an object (evaluating ‘’) TypeError: undefined is not an object (evaluating ‘window.sqlitePlugin.openDatabase’) Error: [$injector:unpr] Unknown provider: $scopeProvider <- $scope Again […]

problems while doing unit testing with controller in angularjs

All the karma configuration are right and it runs fine with other controller files.But it could not run this controller file. I will be thankful if you guys find any solutions for this. 🙂 the screenshot of the source code, testing, and commond prompt are as follows 1. controller file 2. jasmine unit testing file 3. after running karma, error displays command prompt Source: AngularJS

Next Page »