Skip to main content

All Questions

Filter by
Sorted by
Tagged with
1 vote
1 answer
2k views

How to write unit test case of ag agrid cellRenderer with return value in angular

TS: columnDefs = [ { headerName: 'columnone', field: 'one', width: 120, sortable: true, cellRenderer: (data) => { return this.limitCommonUtil.numberFormatter(data?.data?.upperAmount); ...
Ashwini's user avatar
  • 305
1 vote
1 answer
606 views

How can I test that a function was called inside an if statement in jasmine-karma

I'm creating an Angular app and I'm learning unit test and I want to test certain method, but I can't manage to test that the function enters in the if statement. I don't know how to force it. Could ...
Julio Rodríguez's user avatar
1 vote
2 answers
2k views

When to use createSpy, createSpyObject and spyOn?

I have learned recently that spyOn cannot be used with external dependencies and can only be used with System Under Test. But I have some questions regarding why it cant be used and I came up with ...
Linta Sheelkumar's user avatar
0 votes
0 answers
329 views

How to pass a token for jasmine requests

I implemented my tests in an application without authentication, but when it was implemented my tests stopped working. I have an API to generate a token, how can I put this token in my services inside ...
Guilherme Prado's user avatar
0 votes
1 answer
3k views

How can i test a function that return a promise or reject - Jasmine and Karma

I need to cover 100% of the tests of a function, it returns a return new Promise<boolean>((resolve, reject) this is the full function. saveData(): Promise < boolean > { return new ...
Guilherme Prado's user avatar
0 votes
1 answer
551 views

How can i coverage a promise response with Jasmine and Karma

I have a function that returns and treats a promise, I need to cover the return that is inside then but I don't know how I can do this, I'm currently trying as follows: confirmRemoveUser(user: ...
Guilherme Prado's user avatar
2 votes
1 answer
2k views

How to test whether an Angular mat-nav-list contains an element?

I'd like to check whether an Angular mat-nav-list contains an element. I'm able to select it with fixture.debugElement.query(By.css('.items')), but I'm not sure how to check whether it contains ...
saæ's user avatar
  • 183
0 votes
0 answers
273 views

Angular 6 and Karma/Jasmine issue - No Angular CLI

My app is currently on Angular 6.1.9, Karma 2.0.0 and Jasmine 2.4.1. After Angular 6 upgrade, npm test fails. Chrome browser opens to indicate that Karma is connected. But I see EXECUTED 0 OF 0 TEST ...
user3344978's user avatar
0 votes
2 answers
441 views

how to test and resolve Controller data (.then function()) promise and get orginal Data in Jasmine2

I am testing a controller that uses a service that returns a promise. I need to resolve promise. I am using Jasmine 2. Here is Spec code beforeEach(inject(function ($controller, $...
Ajay.k's user avatar
  • 121
2 votes
0 answers
219 views

Angular 5 / Jasmine 2 test setTimeout function only once

my problem is that i have this fonction : loopPingAPI() { this.pingAPI().then( success => { this.setConnected(true); this.stopPingAPI(); ...
Stefan MARTEL's user avatar
0 votes
1 answer
1k views

Mock a provider class to return response and handle promise - Unit Testing with Jasmine and Karma with Ionic 3

Am a newbie in Unit Testing. I started to write Unit Testing for my Ionic 3 Application using Karma and Jasmine. I followed blogs to get the configurations set and successfully tested the ...
Joseph's user avatar
  • 1,080
3 votes
0 answers
895 views

Random number of jasmine tests fail when run together, but they pass individually?

I have around 450 assorted specs written in Jasmine (async & sync) in my codebase. Karma is the test runner which I use for running the tests on a headless chrome browser. Whenever I run the tests ...
ShellZero's user avatar
  • 4,633
0 votes
2 answers
1k views

Angular 6 - mock authState - valueChanges of undefined

I have a service with a property and a getter. The property is set in the service constructor like this: public readonly usersMetaData: Observable<User | null>; constructor(private afAuth: ...
user avatar
0 votes
1 answer
3k views

Angular 6 testing - Jasmine - mock chained promises

Ive got a method register() in my service which I want to test. My assert is that an another method from a injected service is called. Lets have a deeper look into my code: Service export class ...
user avatar
1 vote
1 answer
3k views

How to mock a nested method?

I'm learning more about Jasmine Unit Testing and I've ran into something that I can't figure out. I'm new to both JavaScript and Unit Testing. I've tried to look for examples about nested methods and ...
Dixon Ivey's user avatar
0 votes
1 answer
639 views

Testing Lodash sortBy function argument using Jasmine

I have a controller in my project that goes like this: define(function (require) { 'use strict'; function AllOrgsController($rootScope, $uibModalInstance) { var vm = this; var clonedOrgs ...
DJ22T's user avatar
  • 1,640
0 votes
1 answer
31 views

Test plain javascript file returning different objects

Is it possible to test the code below with Jasmine testing tool or any other npm module like rewire or similar? const AuthValidatorDumb = require('./src/AuthValidatorDumb'); const AuthValidator = ...
ivanb's user avatar
  • 11
0 votes
1 answer
36 views

Unit Test are not failing

I am trying to write unit test cases, for web API call. Which shows success below : Success Unit Test (jsfiddle) getProduct("jsonp","https://maps.googleapis.com/maps/api/e Error Unit Test (...
SmartestVEGA's user avatar
  • 8,849
0 votes
1 answer
94 views

Async Test in Jasmine 2.6

The syntax for async tests has changed since 2.x and the documentation is not clear. Can someone clarify how I execute some code, block for 3 seconds, and then run a test condition using the new ...
Robatron's user avatar
  • 128
1 vote
3 answers
672 views

What's the equivalent of jasmine.createSpy().and.callFake(fn) in sinonjs

I'm looking for the equivalent of jasmine.createSpy().and.callFake(fn) in sinonjs. For example: const mySpy = jasmine.createSpy('my spy') .and .callFake((options) => Object.assign({}, {name: 'foo'...
Ofir D's user avatar
  • 818
0 votes
1 answer
524 views

Jasmine 2.0 unit testing for angularjs factory

I am new to writing jasmine test cases for angularJS factory. I want to test the entire factory, but I'm unable to fetch getKeys. Here's my factory. My Factory is: 'use strict'; var a11yModule = ...
lucky's user avatar
  • 19
0 votes
0 answers
765 views

Call on $state.go not working in unit test

I work on an app based on Angular 1.5, angular-ui-router and WebPack for which I want to make unit tests on module declaration part, especially on state configuration (I want to test source code of ...
Gaëtan Maisse's user avatar
1 vote
0 answers
84 views

How to write jasmine unit test case for chrome.identity.getAuthToken()?

chrome.identity.getAuthToken({interactive: true}, function (token :any) { var url = 'http://" //the code goes here }); I am not able to cover the code inside the getAuthToken function. I have ...
guppie's user avatar
  • 21
0 votes
1 answer
727 views

Runtime unit testing in JavaScript

I've been testing JavaScript code using unit testing frameworks like jasmine and Qunit. But all these testing framework works only at load time, but I want to initiate the test cases at run time, for ...
Bharath's user avatar
  • 101
0 votes
1 answer
334 views

A better way to handle async tests in jasmine 2

This is an example of three of my tests... describe('Enabled button (no disabled attribute)', function () { var el, clicked = false; beforeEach(function (done) { // Create the tag ...
Justin808's user avatar
  • 21.5k
1 vote
1 answer
414 views

Jasmine Async Testing

I'm attempting to test a value that is set asynchronously using Jasmine 2's new done() callback. I've based my test after the example Jasmine gives in their documentation (http://jasmine.github.io/2....
corbin's user avatar
  • 2,797
0 votes
1 answer
1k views

Unit testing promises in AngularJS with arguments

We're unit testing our services and facing issue spying on methods with arguments of dependent services. I am writing unit tests for ServiceA ServiceA.js angular.module("App").service("ServiceA", ...
svp's user avatar
  • 495
1 vote
1 answer
1k views

Jasmine unit test asynchronous controller method

I'm using Jasmine to unit test an Angular controller which has a method that runs asynchronously. I was able to successfully inject dependencies into the controller but I had to change up my approach ...
j_buckley's user avatar
  • 1,936