Search Posts

Category: jasmine

Angularjs unit testing jasmine karma webpack :Error: [$injector:unpr] Unknown provider:

Error: [$injector:unpr] Unknown provider: appConstantProvider <- appConstant <- creditCaseDataService <- gradingData I am unit testing a controller in angularjs running through karma webpack. my controller file ‘use strict’; define([‘appModule’], function (module) { module.controller(‘warningSignalsController’, [‘appConstant’,’$scope’, ‘$rootScope’,’gradingData’, function (appConstant, $scope, $rootScope,gradingData) { var warningSignals = this; $scope.warningAvailCheck = function(value){ var answerWithNoIndex = 0; if(value == null){ return true; } }; gradingData.formatGradingDataForUI().then(function (response) { console.log(response); warningSignals.data = response[gradingData.getSelectedRP()]; }); }]); }); my spec file require(‘index/dcp/controllers/warningSignalsController’) require(‘index/appManager/app’); require(‘index/appManager/constant’); require(‘index/Common/services/gradingDataService’); […]

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 = […]

Test if private method was called in Service

How should I test if AngularJS private method in the $service was called? I would appreciate any help. angular.module(‘login’) .service(‘EventService’, [ ‘$http’, ‘$log’, function ($http, $log) { function sendEvent(category, action, label, value, customParams) { // } return { sendLoginPageEvent: function (action, customParams) { if (!customParams) { customParams = {}; } customParams.template = ‘templateName’; sendEvent(‘LoginPage’, action, null, null, customParams); }, }; }]); I have some tests like these, but don’t seem to work: describe(‘Test of Cookie […]

Unit Testing AngularJS ‘config’ Written in TypeScript using Jasmine

I’m currently trying to Unit Test the config of a new AngularJS component. We are using ui-router to handle the routing in our application. We have been able to successfully test it for all our previous components, but the code for all of them was written in plain Javascript. Now that we switched to TypeScript we are having some issues. This is the TypeScript code where we make the configuration of the module: ‘use strict’; […]

Jasmine – TypeError: undefined is not a constructor

I have an directive for displaying tooltip like follow: angular.module(‘cui.directives.cuiEllipsisTooltip’, []) .directive(‘cuiEllipsisTooltip’, [‘$compile’, ‘$timeout’, function($compile, $timeout) { ‘use strict’; return { restrict: ‘A’, scope: true, link: function(scope, element, attrs) { var raw = element[0]; var hasTooltip = false; var leaveEventPromise = null; element.on(‘mouseenter’, function() { if (raw.offsetWidth < raw.scrollWidth) { if (hasTooltip) { scope.enabled = true; } else { scope.tooltip = element.text(); scope.enabled = true; element.attr(‘data-toggle’, ‘tooltip’) .attr(‘data-original-title’, scope.tooltip) .removeAttr(‘cui-ellipsis-tooltip’); $compile(element)(scope); hasTooltip = true; element.tooltip(‘show’); […]

dependency issue in Karma and jasmine

I want to use Karma and Jasmine to test my AngularJS application. I have installed all things which is related to karma. In the karma.conf.js file, I have given gulped bower.js(which will contain all bower component) and gulped all.js(all js files) and testcase file. But I am getting one dependency issue which is not allow me to move further. If I write simple test case without using beforeEach, it will get execute perferctly. But I […]

Unit test nested promise angularjs/jasmine

I am trying following snippet code, to simplify it, I have removed most of the unwanted code. function functionToTest() { if(hasUnsavedChanges()){ return customService.confirm().then(function(confirmed) { console.log(confirmed); if(confirmed) { return customService.openSomething().then(function (data){ console.log(data); return customService.doneSomething(); }); } else { return customService.doSomething().then(function (){ return customService.doSomethingBeforeDone().then(function (){ return customService.doneSomething(); }); }); } }, function() { return customService.doneSomething(); }); } else { return customService.doneSomething(); } } Here is my unit test when hasUnsavedChanges() returns true it(‘should doSomething’, function() { spyOn(customService, […]

Expect condition inside the .then won’t execute

I’m using PageObjects in Protractor tests. Structure looks like this, e2e specs base.po.ts // Base PageObject class Login login.e2e-spec.ts // contains describe, it blocks etc. and Expect conditions. login.po.ts // Interacts with page elements I’m returning Promises from methods inside PageObject file. And then inside spec file in it blocks i’ve Expect conditions. A sample code is like, // login.e2e-spec.ts it(‘should logout’, () => { console.log(‘—- step 1 —-‘); page.logout().then(function () { console.log(‘—- step 4 […]

AngularJS + Karma-Jasmine: Unexpected Request + UI Router

I am trying to Unit Test an AngularJS HTTP Service with the help of Karma-Jasmine. But I am facing the following Error from Karma: Error: Unexpected request: GET app/license/license.html I Googled and found out that it has something to do with ui-router. The following StackOverflow Link: (UI-router interfers with $httpbackend unit test, angular js) suggests some Answers, but none of them works for me and the Error remains the same. I am posting my code […]

Error: [$injector:unpr] Unknown provider, a "Provider" Suffix is added automatically

I’m trying to create a unit test component for my AngularJS component, but I’m getting the following error thrown Error: [$injector:unpr] Unknown provider: CurrentMarketProvider <- CurrentMarket http://errors.angularjs.org/1.5.0/$injector/unpr?p0=CurrentMarketProvider%20%3C-%20CurrentMarket Here’s is the unit test component, I’ve searching around a bit, found that might have been cause because of the arrangement of the injected components, tried to rearrange them, with no luck. describe(‘eduController’, () => { describe(‘eduController’, () => { beforeEach(angular.mock.module(‘components/edu/edu.template.html’)); beforeEach(angular.mock.module(‘test-edu’)); let element, $location, scope, $rootScope, $componentController, […]

Next Page »