All Questions
Tagged with jasmine2.0 unit-testing
28 questions
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);
...
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 ...
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 ...
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 ...
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 ...
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: ...
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 ...
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 ...
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, $...
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();
...
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 ...
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 ...
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: ...
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 ...
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 ...
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 ...
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 = ...
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 (...
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 ...
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'...
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 = ...
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 ...
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 ...
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 ...
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
...
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....
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", ...
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 ...