Search Posts

Category: karma-webpack

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’); […]

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

How to include karma and jasmine to AngularJs project served with webpack

I spent the whole day trying to setup karma for my project. I went through all the tutorials and StackOverflow but couldn’t integrate it into my project. My project is served using web pack. I guess the problem is that I can’t get the reference to my root app module. Please help me with this. I tried importing the module using its name, imported the whole files(js) etc but nothing helped. PS: This project has […]

Unable to run angular4 test cases

I am getting an error (p.s. attached screenshot) when I run ng test in my angular4 app. I have not changed anything as such this just added some test specs in app.component.spec.ts My karma.config.js file has following code module.exports = function (config) { config.set({ basePath: ”, frameworks: [‘jasmine’, ‘angular-cli’], plugins: [ require(‘karma-jasmine’), require(‘karma-chrome-launcher’), require(‘karma-remap-istanbul’), require(‘angular-cli/plugins/karma’) ], files: [ { pattern: ‘./src/test.ts’, watched: false } ], preprocessors: { ‘./src/test.ts’: [‘angular-cli’] }, mime: { ‘text/x-typescript’: [‘ts’,’tsx’] }, […]