Search Posts

Category: unit-testing

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

angular unit test cannot load html template

Jhipster project(angular 4) blocked in unit test. below is my compontent.ts import { Component, OnInit, Input } from ‘@angular/core’; import { Observable } from ‘rxjs/Observable’; import { ReportListService } from ‘./report-list.service’; import ‘rxjs/add/observable/timer’; @Component({ selector: ‘gffr-report-list’, templateUrl: ‘./report-list.component.html’, styles: [require(‘./report-list.component.css’)] }) export class ReportListComponent implements OnInit { reportNames; constructor( private reportListService: ReportListService) { } ngOnInit(): void { const timer = Observable.timer(2000, 1000); timer.subscribe(t => { this.reportListService.checkReportFolder().subscribe((data) => { if (data.status === 200) { this.reportNames = […]

How to just mock the Controller without mocking the Dependices

I have an HTML file like this <div class=”textoutput”> <div ng-controller=”TestController”> <div class=”textdiv”> <div ng-repeat=”row in contactperson”> <div ng-if=”contactperson.name”> <input type=”text” name=”conTitle1″ ng-model=”contact1.title” ng-pattern=”/^[a-zA-Z0-9_- ]*$/” ng-maxlength=”10″ maxlength=”10″ value=”” required> </div> </div> </div> </div> </div> I am trying to mock the Controller for testing the HTML without calling the dependencies it has but it’s always showing me Controller is not defined beforeEach(inject(function ($compile, _$rootScope_, $templateCache, $http, _$controller_) { $scope = _$rootScope_; $controller = _$controller_; var directiveTemplate […]

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

In Angularjs how do you alter a mock service per test?

Code example This is probably better explained in code, so I have included a detailed, abstracted example below – where my question is repeated in the comments. Example Summary For example, you mock out a reasonably complex mock service, and in the first test you want the mock service to give a positive result for one function (by return code 200 in the example below). In the second test, you want the same function to […]

Why won’t "ng test" find my unit tests within npm packages?

I recently upgraded my team’s enterprise application to @angular/cli 1.4.5, and since then have not been able to run unit tests on the code within our private npm packages. Prior to the upgrade I had no problems running my unit tests, but ng test now only picks up unit tests located within src/app. Included are the src/test.ts file and karma.conf.js file, as well as the console output when trying to run the contexts from the […]

Test angularjs with Jasmine using stand alone command line interface

I have a simple .js file and its test on Jasmine. I’m able to run the test successfully through Jasmine’s stand alone SpecRunner.html. Is it possible to do the same on command line interface? I do have node installed along with jasmine, npm install -g jasmine Tests using Jasmine Command line interface works for simple javascript functions that return simple objects. However if I start using angular libraries, it results in: })(window, document); ^ ReferenceError: […]

Jasmine / Karma test error using angular.mock.inject

I am trying to run some Angular karma/jasmine tests to test functionality for ui-grid. But my issue is that my tests are breaking when they get to the injector.Here is my error: C:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:280261 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:11940 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:277471 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:139593 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:1071148 [email protected]:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:1069633 C:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:1007389 TypeError: undefined is not a constructor (evaluating ‘$compile(‘<bss></bss>’)’) in C:/Users/schmitzb/Projects/RCO/rco-project/test/index.js (line 9) C:/Users/schmitzb/Projects/RCO/rco-project/test/index.js:9:1008235 I’m doing something incorrectly at this line I believe, when I remove this line and put in a different module it doesn’t error: […]

When i am testing the application i am getting this error No component factory found for AlertModal

Code: this.modalRef = this.alertService.open(AlertModal,this.logoutScreenOptions); this.modalRef.componentInstance.messageObj = {type : ‘basic’, title: title, message: msg}; this.modalRef.result.then((result) => { }, (reason) => { console.log(“Closed with “+reason); }); @NgModule({ entryComponents: [ AlertModal ] }) Error: Error: No component factory found for AlertModal. Did you add it to @NgModule.entryComponents? at noComponentFactoryError (http://localhost:9876/base/src/test.ts?255649f9a1a6edbb610949c0145114536ad2d17e:3704:34) at _NullComponentFactoryResolver.Array.concat._NullComponentFactoryResolver.resolveComponentFactory (http://localhost:9876/base/src/test.ts?255649f9a1a6edbb610949c0145114536ad2d17e:3722:15) Source: AngularJS

Next Page »