Search Posts

Category: karma-runner

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

Jasmine TypeScript unit test fails if types in methods being tested are not fully qualified

So I have successfully got unit testing working with my angularjs app using Jasmine and Karma. However, I’ve just hit an annoying issue I can’t figure out. So I have a controller with a very simple method like this (this is a random example so don’t worry if it seems weird): public ExecuteUserCreatedCommand( id: number, userId: string) { const command = new Commands.UserCreated(); command.Id = id; command.userId = userId; return this.CommandService.UserCreated(command); } Note that the […]

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

Karma unit test failing TypeError: undefined is not an object (evaluating ‘that.options.length’)

I have an AngularJS application that I’m trying my hand at unit tests, although I’m stuck at my first hurdle. I keep getting the following error TypeError: undefined is not an object (evaluating ‘that.options.length’) when running the below controller and unit test. I dont see where the undefined is and any help would be appreciated. controller function dropdownController() { const that = this; let selected = ”; that.$onInit = () => { if (that.options.length) { […]

Cannot call beforeEach ‘inject’ on angularJS (FUSE Admin) unit testing using karma

I used FUSE Admin app on my project – http://fuse-angular-material.withinpixels.com/apps/dashboards/project. I already checked other samples and even run this code on a different project and works just fine. IT’s just that I cannot inject the service, controller etc. on ‘beforeEach inject’, thus I cannot cont. my test. I don’t know what’s wrong or did I miss something (dependencies? not sure) while running this on FUSE. Do you have any idea? Here’s my code. SERVICE (the […]