Category: jasmine

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

Unit testing that a component is rendered in an angular app

I have an Angualr 1.5 app that looks like this. The app has a mix of Typescript and Javascript components: import * as angular from ‘angular’; import {B} from ‘./b.component’; import {A} from ‘./a.module’; export const c= ‘c’; angular.module(c, [a]) .component(B.componentId, new B()); The corresponding HTML looks like this <div> <div id=”holder”> <a></a> </div> </div> And here is the b.module angular.module(a, []) .component(b.componentId, new A()); And here is the a.component import * as ng from […]

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 this plunk I have an Angular/Jasmine test that attempts to mock a service function. The service function mocked needs to be invoked by another function in the service. This is the error I get: Error: getTheDate() method does not exist And this is my attempt, where the function tested getTheMonth should invoke a mocked function getTheDate, it seems that spyOn is used incorrectly: angular.module(“mymodule”, []) .service(‘myService’, function(){ this.getTheDate = function() { return new Date(); […]

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

How to fix the error ‘Module is not available! You either misspelled the …’

I’m only using Angularjs and Jasmine. I got an error Module is not available! You either misspelled the … and i’m looking to fix it without success. my-template.html <html ng-app=”myApplication”> <head> <script src=”lib/scripts/1_4_4/angular.min.js”></script> </head> <body> <div ng-controller=”SimpleController”> {{amount.length}} </div> <script> var myModule = angular.module(‘myApplication’, []); myModule.controller(‘SimpleController’, function($scope) {$scope.amount = [‘a’,’b’,’c’]; }); </script> </body> </html> my-template.spec.js describe(‘a simple controller’, function(){ var $scope; //See API angular.mock.module beforeEach(module(‘myApplication’)); beforeEach( inject( function($rootScope, $controller ){$scope = $rootScope.$new(); […]

How to mock chained promises using Jasmine?

I am writing a unit test to a method that contains this piece of code: Name.get($scope.nameId).then(function(name){ Return name; }).then(doSomething); The function doSomething(name) looks like this. function doSomething(name){ addNametoList(name); } I don’t need to test this part of the code. Since I can’t just ignore it in my test (or can I?), I need to mock it. I mocked the first promise spyOn(mockName, ‘get’).and.returnValues($q.resolve({“Mike”})); and thought that it would propagate through the second then(doSomething) but name […]