Search Posts

Category: karma-jasmine

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

Getting an Error: [$injector:modulerr] Failed to instantiate module App in angularjs + karma + jasmine project

We have a huge project with multiple controllers, factories,configs etc and recently i started to integrate karma+ jasmine to write unit test cases. However I get the above error. I read multiple solutions and injected the module in multiple ways but still get similar or multiple errors. I want to test my factories, controllers, config but even following multiple tutorials didn’t fixed my issue and I dont understand it either. Can someone help? app.js var […]

Karma launches and closes itself in chrome

I am testing Angular sing Jasmine and Karma. The tests seem to run perfectlyand I am able to see teh results in the Windows console. But anyway is there a way to make Karma stay opened and not close itself after 2 seconds?? I have this configuration of karma.config.js: const webpackConfig = require(‘../../../webpack/webpack.test.js’); const WATCH = process.argv.includes(‘–watch’); module.exports = (config) => { config.set({ // base path that will be used to resolve all patterns (eg. […]

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

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

TypeError: undefined is not a constructor (evaluating ‘angular.controller(‘myView’)’)

I’m getting the below error while doing karma/jasmine unit testing for both the test cases.I tried by modifying the controller by adding angular.controller in the spec file even then it is not working.Is there any way to fix? TypeError: undefined is not a constructor (evaluating ‘angular.controller(‘myView’)’) myView.spec.js // myView.spec.js (function(){ describe(‘controller: myView’, function(){ var module,myView,$q, $rootScope, $scope, uiGridConstants, overviewService, commonService, $timeout; beforeEach(function() { module = angular.module(‘app.myView’); controller= angular.controller(‘myView’) }); beforeEach(inject(function ($controller, _$q_, _$rootScope_, _$timeout_) { […]

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

AngularJS + Karma + Jasmine: beforeEach() – angular.module vs angular.mock.module

I am new to Jasmine and Karma testing. I am trying to Unit test AngularJs Service. While writing Specs, I came around two types of Code for injecting Module. 1st Type beforeEach(angular.mock.module(“app”)); 2nd Type beforeEach(function () { angular.module(“app”); }); Can anybody explain the difference between the above two in simple plain English with a simple example. And also, which code to use in what kind of scenario? I tried to Google it, but was not […]

Unit testing a notify callback from a promise

I am calling promise based function that returns a notify callback so I can update progress in the UI. const deferred = this.$q.defer(); const Upload = this.Upload.upload({ url: ‘api/file-uploads’, data: { file: file } }); Upload.then((response) => { return deferred.resolve(response.headers().location); }, (response) => { return deferred.reject(response.status); }, (evt) => { this.$rootScope.$broadcast(‘upload-progress’, { uploadProgress: (<any>parseInt)(100.0 * evt.loaded / evt.total) }); }); I am struggling to figure out how to cover this callback in a unit test, […]

Next Page »