Search Posts

Category: jasmine

How do I reference another module in typescript?

I’m having a problem with import and module in typescript 2.4.1. I have two files: testAdd.ts: module mymodule { export class myClassAdd { static add(left: number, right: number): number { return left + right; } } } testCallAdd.ts: //import ‘someLibrary’; module mymodule { export class myClassCallAdd { static callAdd(): void { let result: number = mymodule.myClassAdd.add(3, 4); //error here } } } This code as it is now compiles fine. I’ve found that if I […]

Why am I not getting status code in Jasmine test case?

I am doing a rest call in a following manner updateOperation = function (UUID) { var deferred = $q.defer(), restApiPath = restApiBasePath + UUID + “/_update”, updateSuccess = function () { deferred.resolve(); }, updateFailure = function (errorObj) { deferred.reject(errorObj); }; xyzService.invokeREST(“PUT”, restApiPath, updateSuccess , updateFailure ,true); return deferred.promise; } And my test case looks like this it(“should call update & resolve promise when http response is”, function() { $httpBackend.expectPUT(getValidURL).respond(200, true); taskService.updateOperation(UUID).then(function(status,data){ expect(status).toEqual(200); }); $httpBackend.flush(); }); […]

Jasmine Spy : Getting an error in returnValue

I am trying to write unit test case with jasmine spy. Below is my service code. function reset(someParam) { var deferred = $q.defer(); svcTypes.getTasksWithRoles().then(function (types) { if (types.HadError) return; // do some stuff.. deferred.resolve(results); }, function (errorResponse) { deferred.reject(errorResponse); }); return deferred.promise; } Below is my unit test case : describe(‘tests for svcWorkordertypes’, function () { beforeEach(angular.mock.module(‘workorders.service’)); beforeEach(angular.mock.module(‘workordertypes.service’)); var svcWorkordertypes; var svcTypes; var $q, $httpBackend; beforeEach(angular.mock.inject(function (_svcWorkordertypes_, _svcTypes_, _$q_, _$httpBackend_) { svcWorkordertypes = _svcWorkordertypes_; svcTypes […]

Testing JS callback with timeout using Jasmine

I need to test some code in Angular with Jasmine, but the thing is that I can’t do this because of $timeout call. So the code looks like this: $scope.add = function() { SomeService.add(id, function() { $timeout(function() { $scope.showSuccessMessage(); }, 1000) }, function() {}) }; So the test code is: describe(‘method add’, function() { it(‘should add’, function() { spyOn(SomeService, ‘add’).and.callFake(function(id, successCallback, errorCallback) { spyOn(scope, ‘showSuccessMessage’); successCallback(); expect(scope.showSuccessMessage).toHaveBeenCalled(); }); scope.add(); expect(SomeService.add).toHaveBeenCalled(); }); }); And the problem […]

Protractor: httpGet is not defined; Need Response codes from Hyperlinks

Problem: I am able to count the number of links on a page. I want to test if they are valid. While I could use .click -> this would validate a hyperlink thats a “404 Page Not Found” to Protractor. I want to use error code or response codes. There are several SO answers on this, but for some reason none of them work all based around two errors: Cant use the http get module […]

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 »