Skip to main content

All Questions

2 votes
1 answer
818 views

Checking if multiple elements are rendering using jasmine

it('should check if all div are appearing which are dependent on a common condition', () => { component.someCommonCondition = true; fixture.detectChanges(); // now the prob lies in line below ...
Ankur Aggarwal's user avatar
1 vote
0 answers
496 views

Mock a function present in angularJS controller using jest - testing

I've a small controller written in angularJS. 1st function is actually calling a 2nd one to perform a calculation and return it back. I want to mock the 2nd function in my testing, so that it returns ...
Shaswat Kumar's user avatar
0 votes
1 answer
421 views

Pass data from one it block to another

As you can see in the above image, controller value assigned in first it block is not the same anymore in second it block. Is this the default behavior? Can we do some changes in karma config file to ...
jay rangras's user avatar
0 votes
1 answer
36 views

Unit testing promises triggered by $watch

I'm using Jasmine to try and test code which has the following pattern: (this is essentially a paginated database table load) 1. controller calls api on load 2. api.then updates $scope variable 3. ...
Matt Wilde's user avatar
0 votes
1 answer
230 views

i want to write unit test case for my angular js app

I have a weather app that uses https://metaweather.com/api/ to fetch the weather the js code is as angular.module('ourAppApp') .controller('MainCtrl', function($scope,apiFac) { $scope.displayCity ...
shiva's user avatar
  • 1
2 votes
0 answers
134 views

Why can my ng-blur call function correctly but won't pass the unit test? Jasmine

I tested my code on the server and it will call the pinNameEditBlur correctly when I make the textbox blur, but it won't pass the unit test here. The error for the unit test is pinNameEditBlur is not ...
dead_programmer's user avatar
0 votes
1 answer
134 views

How to test nested ng-click using Jasmine

I have an HTML which is something like this: <li ng-show="obj.displayTab" role="tab"> <a tabindex="0" ng-click="abc($event)"> NAME &...
Abhid's user avatar
  • 274
0 votes
1 answer
2k views

Is there way to spyOnProperty window.location.search using jasmine unit testing? because search is not configurable

Its throwing error: search is not configurable it('should have search keyword', function () { spyOnProperty(window.location, 'search').and.returnValue("?q=jag"); expect(window.location....
srikanth's user avatar
0 votes
1 answer
182 views

How to get ng-model value of Radio button using Jasmine and Karma in AngularJS 1.x

I am new to Jasmine and Karma I am testing an AngularJS application using Jasmine+Karma My Html looks like this: <div id="form"> <div id="car-type"> <input type="radio" ...
CoderPJ's user avatar
  • 1,011
1 vote
1 answer
1k views

toHaveBeenCalled is not working correctly with two Jasmine test cases on same spy

I have a spy object which I have used in two test cases. I am using toHaveBeenCalled method to check the spy method is called or not. My code is working perfectly fine when used with one test case ...
Yuvraj Patil's user avatar
  • 8,804
4 votes
1 answer
12k views

Error: Expected undefined to equal in karma

Test Case File describe('homeController', function() { beforeEach(module('moduleInjectionApp')); var $controller; var $rootScope; beforeEach(inject(function(_$controller_, _$rootScope_) { $...
ANKIT DHORELIYA's user avatar
0 votes
2 answers
47 views

Updating template and calling $digest does not trigger $watch with correct parameters - unit tests angularjs

I have a simple directive which adds or remove focus class to element based on directive's scope property. I would like to write 2 tests. First test verify, that focus class is on element when ...
mimo's user avatar
  • 6,867
0 votes
1 answer
56 views

Testing how many times a method was called from another method's return statement in AngularJS

Newbie to JS. I have this function. First, it checks for data in cache. If it's not there, it calls backend for this data and saves it to cache. function doSomething() { return getCachedData() ...
Mr P's user avatar
  • 157
0 votes
1 answer
750 views

How to mock a static function with Jasmine?

How can I spy on the focus() and select() functions within Jasmine (Unit testing)? My function: static nextFieldOnAlt(e) { if (e.keyCode === 18) { const focusableFields = ...
can's user avatar
  • 214
1 vote
0 answers
48 views

Unit testing a form element with Jasmine and Karma in AngularJS for $setPrisrine()

I have a input form element as below in my HTML: <form name='myForm'> <input type="text" id="description" name="description" ng-model="vm.description" /> </form> And ...
Avinash Gayam's user avatar

15 30 50 per page
1
2 3 4 5
79