Search Posts

Category: unit-testing

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); = response[gradingData.getSelectedRP()]; }); }]); }); my spec file require(‘index/dcp/controllers/warningSignalsController’) require(‘index/appManager/app’); require(‘index/appManager/constant’); require(‘index/Common/services/gradingDataService’); […]

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

Some of your tests did a full page reload – Unit Testing

I’m relatively new to unit tests so forgive me. But I’m getting the following error and have been looking around for a solution but can’t really understand the examples I’ve seen. Error: Some of your tests did a full page reload! This is my test causing the issue. it(‘should download test results’, () => { expect(scope.downloading).toBeFalsy(); httpBackend .expectGET(‘’) .respond(mockedProductTest); controller.DownloadResults(); expect(scope.downloading).toBeTruthy(); httpBackend.flush(); expect(scope.downloading).toBeFalsy(); }); This is my function. this.$scope.downloading = true; this.$http.get( `${this.$config.serverAddress}downloads}` ) .then(response […]

Angularjs – How to import Bootstrap into Karma-Jasmine for testing

I have a directive that call a method from bootstrap.min.js and when I write a test file to test it it render the error say that the function I used is not defined. I think the reason which cause this error is because I didn’t include Bootstrap in test enviroment.I searched many times on Google but have not find a way to get Bootstrap work with Karma-Jasmine. Does any know a way how to do […]

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$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, […]

Unit testing HTTP manager wrapper service

I have an HTTP manager wrapper service, which I is getting used by api services internally. Not I am wondering How I can test this wrapper services. any suggestions? angular.module(‘PpmApp’) .factory(‘httpManager’, [‘$injector’, httpManager]); function httpManager($injector) { var $http = $injector.get(‘$http’); var $q = $injector.get(‘$q’); var preloaderService = $injector.get(‘preloaderService’); var constantsProvider = $injector.get(‘constantsProvider’); var service = { getRequest: getRequest, postRequest: postRequest, putRequest: putRequest, deleteRequest: deleteRequest, fileUpload: fileUpload }; var loader = true; return service; function getRequest(params) […]

Test scope variables inside a non-scope method that is initiated inside if condition.

Code: if($scope.someValue){ init(); } var init = function(){ $scope.anotherVal = true; } Test case:———————— describe(‘test 1’, function(){ it(‘spec 1’, function(){ //I could’nt figure out how to initiate the init() method? $scope.someValue = true; expect($scope.anotherVal).toEqual(true); }); }); //error: Expecting undefined to equal to true. Can anyone help me figure out how to initiate the init() method. Moving the if condition into another method is not an option. Source: AngularJS

How do you use unit test a factory using $provide and $q

I’m trying to write a unit test for a service that has a dependency on another factory function that returns a promise. I’ve followed the process as seen in this question and answer, but for some reason the code in the then() that I’m trying to verify isn’t being called. How do I get this to work? I’d like to use the version that is not doing the spyOn if possible (the Update section in […]

Angularjs Karma check url param is present

I’m new to unit tsting and trying to write a unit test for my app. My Route is : { name: ‘details’, url: ‘/accounts/company/:companyId’, controller: ‘controllere’, templateUrl: ‘templateurl’, } My Controller : if (!$stateParams.companyId) { $scope.promise = $state.go(‘home’); } else { // get company details } In my unit test I need to test if “companyId” is present in the URL, then only proceed with the rest else redirect to “home”. I tried this code […]

Next Page »