Questions tagged [karma-jasmine]

Karma-Jasmine is an adapter for the Jasmine testing framework, which is shipped with Karma by default.

Filter by
Sorted by
Tagged with
0 votes
1 answer
52 views

TypeError: Cannot read properties of undefined (reading 'nativeElement') for reading html element in jasmine for angular

below case is failing have same scenario in other place its passing it('login lables', () => { const terms = fixture.nativeElement as HTMLElement; expect(terms.querySelector('#...
venkat0107's user avatar
0 votes
0 answers
8 views

How to testing nested custom reactive component in Angular with jasmine-karma

I have a question please, I have a parent and a child components. Here is the .ts @Component({ selector: 'app-parent', templateUrl: './parent.component.html', styleUrls: ['./parent.component....
L. Kvri's user avatar
  • 1,522
0 votes
0 answers
14 views

How to run specific tests with Karma?

Problem, I have a huge project with many tests that are redundant, and some not. So i need to be able to run specific tests that predefined by a config file or a simple variable that contains a list ...
RoyBarOn's user avatar
  • 961
1 vote
0 answers
13 views

Problems with SignalR when running karma in Angular app

I have an issue when trying to setup karma in a angular project. I get an error when running ng test. It's my first time working with angular and karma. I already checked other stackoverflow posts but ...
natalieDeveloper's user avatar
0 votes
0 answers
14 views

How to configure karma.conf.js to run tests in Angular - Electron application?

I'm trying to configure karma to run tests for Electron (nodejs) and Angular code. This configuration works only for Angular ( ng test ) part of code but completely doesnt work for Electron part. I ...
Spam Garbage's user avatar
0 votes
1 answer
41 views

Angular 16 test guard DI Function

I have a guard that tests if the user is logged in or not and check his user context export function authenticationGuard(userContext: UserContextService): CanActivateFn { return async (_next: ...
dna's user avatar
  • 506
0 votes
0 answers
31 views

Angular tests - Exclude specific spec files

I have errors in some spec files of Angular project and want to exclude them from compilation. I've put these files in exclude of tsconfig.spec.json: { "extends": "./tsconfig.base....
Amphyx's user avatar
  • 677
-1 votes
0 answers
40 views

TypeError: Cannot read properties of undefined (reading 'toString') in jasmine test case in angular

`I am new to angular Jasmine testcases, I have ngOninit in component.ts file while I am running component.ngOnInit() inside should create function. It gives error TypeError: cannot read properties of ...
New tech User's user avatar
0 votes
1 answer
29 views

Create Angular unit tests in components where the dom is manipulated by the typescript

I'm working on creating a ui library in Angular 16, when for the creation of a component such as a textarea in my typescript I go to manipulate the dom of an element at a logical level there are no ...
Salvatore Lorello's user avatar
0 votes
0 answers
19 views

Karma with jasmine does not print any useful error

There is an angular 15.2 project with karma + jasmine tests. The tests are failing in jenkins and there is virtually no information why. Chrome Headless 117.0.5938.132 (Windows 10): Executed 4 of 227 ...
Leos Literak's user avatar
  • 8,969
-1 votes
1 answer
23 views

Implement Angular Test with L10nTranslate

I'm trying to implement tests with Karma in an Angular Application. I'm facing an issue beacuse my component uses L10nTranslate so i tried to import the module into my test file My Component @...
Marvin Valke's user avatar
0 votes
0 answers
22 views

How to test that subscription?

How to test subscription inside function, form is an NgForm --> (FormGroupDirective) and form is scoped inside formChanges function. formChanges(form: FormGroupDirective) { form.control.get('...
pacocom's user avatar
  • 180
0 votes
0 answers
10 views

I am using jasmine framework with Phantomjs. getting error while running test case "Expected an identifier but found 'jasmineRequire' instead"

I am using angular 14 version. test case framework is jasmine and using Phantomjs broswer on karma file while running test I am getting these two errors Expected an identifier but found '...
Keerthana C's user avatar
0 votes
1 answer
32 views

Getting Error Cannot read properties of undefined (reading 'subscribe') in Unit testing

I'm trying to write a Unit test for my component in angular but when it calls an Api it getting undefine from reponse and i don't know how to handle this because it's my first time writing a unit test ...
priyansh kasera's user avatar
0 votes
1 answer
43 views

How to write a unit test for a subscription inside a position strategy?

I'm working on an Angular application and I have a directive where I create a position strategy using the Angular CDK Overlay. Here's a simplified version of my code: const positionStrategy = this....
Irin's user avatar
  • 1,276
0 votes
1 answer
33 views

Test case about multiple mat-select and mat-option

it('should update control2 options when control1 is changed to "b"', (() => { const control1Select = fixture.nativeElement.querySelector( 'mat-select[formControlName="control1"...
Parth Gondaliya's user avatar
0 votes
0 answers
24 views

Testing NGXS state, Uncaught ReferenceError: Cannot access 'State' before initialization

hope I find you well. I am trying to unit test a NGXS state in Angular. I was already able to test all other states, but this one keeps returning: An error was thrown in afterAll Uncaught ...
igryn's user avatar
  • 13
0 votes
1 answer
18 views

Angular unit test failing even when configuring correctly spies

My component looks like this: constructor( private readonly dialogRef: MatDialogRef<ChangeRolesDialogComponent>, private readonly rolesService: RolesService, private readonly ...
Julio Rodriguez's user avatar
-1 votes
0 answers
29 views

Karma is not executing Jasmine test cases in jsdom. Jsdom launched and connected socket.Got "webkit window error,Disconnected,no message in 30000 sec'

enter image description here Test cases not running. Angular 16. Jsdom browser in karma config file Expecting run angular test cases in jsdom browser without others browsers like puppeteer, chrome, ...
Mani Kanta's user avatar
0 votes
0 answers
18 views

Karma Jasmine Tests with SpyOn run fine in browser, but error with 'is not declared writable or has no setter' on auto re-run when a change is made

I have a suite of tests that run completely fine in the console and during the first run after starting up the browser session (i.e. karma start). But once I make a change and the browser session auto ...
Jmh2013's user avatar
  • 2,665
0 votes
1 answer
154 views

How to add a Karma plugin to an Angular 16 that has no karma.conf.js

I have an Angular projects which I created using the v16 CLI. All the unit tests locally fine using ng test. I now wanted to set these up to run on out build machine that runs teamcity. In previous ...
peterc's user avatar
  • 7,163
0 votes
1 answer
45 views

ng test -code-coverage is throwing Disconnected Reconnect failed before timeout of 2000ms after migrating to ANGULAR 14

This is happening only after upgrading to angular 14. This I have tried. All the tests are running successfully but at the end I am getting the below error. Chrome Headless 117.0.5938.132 (Windows 10) ...
sai's user avatar
  • 1
0 votes
2 answers
41 views

how to write unit test in angular service that call http in constructor and fill property?

I am new in angular unit testing; I want to write a unit test for the service that is injected in constructor and is called http in it . but I don't know why globalConfig property is undefined: @...
ali's user avatar
  • 11
0 votes
1 answer
37 views

How to mock ngrx factory selector in testing usng jasmine

I am using ngrx store for state management and writing test cases for a component which is using a factory selector and in the test cases i need to pass a mock data cutomer.selector.ts export const ...
Satyam Kumar's user avatar
0 votes
0 answers
42 views

How to run Angular Jasmine Tests in an Azure Pipeline?

I have a need to run Jasmine tests for Angular on an Azure Pipeline. I am using a Red Hat Enterprise Linux agent. By default Angular uses Karma to run the tests in headless mode using Chrome. The ...
Greg Finzer's user avatar
  • 6,784
0 votes
0 answers
10 views

Angualar Interceptor Test client side

How Can I test this line // client-side error --> message = error.error.message; If I use httpTestingController .expectOne('/path') .error(new ErrorEvent('404 Error'), errorResponse); Always go to ...
pacocom's user avatar
  • 180
0 votes
0 answers
39 views

Angular 16 Jasmine Error: Expected one matching request for criteria, found none

I have seen lots of questions about this error but having spent the best part of today trying each solution out I need your help. I have a function that I use to send data from a form to a URL (not ...
marocena26's user avatar
0 votes
1 answer
45 views

Angular 12: ng test - code coverage : TypeError: Cannot read properties of undefined (reading 'initialize')

I'm getting error code coverage console: TypeError: Cannot read properties of undefined (reading 'initialize') I'm calling service method to component.ts file component.ts file this.myAuth = this....
Nagarjuna Tamarada's user avatar
0 votes
1 answer
21 views

Expected a spy, but got Function with using spyOn()

Using Angular and Karma/Jasmine I am getting ERROR: 'Unhandled Promise rejection:', '<toHaveBeenCalled> : Expected a spy, but got Function.. But from what I can tell, I am spying on the method ...
dman's user avatar
  • 10.5k
0 votes
1 answer
32 views

Angular: No provider for component, [multiple Angular HTML elements] is not a known element

I am currently getting the following unit test failures: 'mat-card' is not a known element (used in the 'ChatCardComponent' component template): 'app-card' is not a known element (used in the '...
FortySix's user avatar
1 vote
0 answers
24 views

How to cover reactive form control optional chaining in Jasmin test cases

submit() { let name = this.form.get('name')?.value } how to cover the ?. operator ? I tried setting form values null : it('makes expected calls: show unsaved message', () => { const ...
Anamika's user avatar
  • 11
0 votes
0 answers
39 views

Angular - Testing window.href.location

I am doing unit tests for my Angular app. I have a service that calls window.location.href = <URL> When I try testing the code it returns an error: Chrome 117.0.0.0 (Windows 10) ERROR Some of ...
igryn's user avatar
  • 13
0 votes
0 answers
20 views

Angular Karma Coverage No specs found

I'm using Angular 15.2.9, Korma and Jasmin for testing I'm integrating sonarQube, which works almost perfectly, I can't make the test coverage work. I know why, because when I throw ng test --code-...
Tortue's user avatar
  • 1
0 votes
0 answers
59 views

Uncaught TypeError: __webpack_require__(...).context is not a function - Karma Jasmine Error in Angular V16

When I try to run tests in Angular V16, I get the following error. An error was thrown in afterAll Uncaught TypeError: webpack_require(...).context is not a function TypeError: webpack_require(......
danushka eranga's user avatar
1 vote
2 answers
68 views

unit test : CombineLatest - test succeedes after adding SetTimeOut

I'm trying to test this method: myMethod() { result$ = combineLatest([observableOne$,observableTwo$]); result$.subscribe(([one, two]) => { this.result = one || two; ...
wael jawadi's user avatar
0 votes
1 answer
147 views

Writing unit tests for simple Angular functions which using inject() method in Angular 16

After Angular CanActivate interface became deprecated, I've changed my guards for simple const functions based on official documentation. For example here is my inverseAuthGuard method, which seems ...
faklyasgy's user avatar
  • 828
0 votes
1 answer
73 views

Jasmine test case for checkbox event handler Angular 16, jasmine 4.3.5

I have to test below function addAll($event: any) { this.Deletion = []; if ($event['srcElement']['checked']) { this.Model.forEach(file => { this.Deletion.push(file.docId); ...
Sagar's user avatar
  • 158
1 vote
1 answer
32 views

Karma Angular Unit test how to create unresolved promise and resolve it in single test to check if code in then was only runned after resolution

I have on promise function waitUntilIsReady: (...) private inProgressSubject = new BehaviorSubject<boolean>(true) waitUntilIsReady(): Promise<void> { const untilInProgress = ...
Tantol's user avatar
  • 13
0 votes
0 answers
28 views

Karma testing using selenium docker containers

I've been tasked with fixing a CI pipeline at work. Additionally, the pipeline should be switched to docker and use selenium browser containers (for example selenium/standalone-edge). I hit a ...
Euklios's user avatar
  • 557
1 vote
0 answers
45 views

TypeError: this.modal.nativeElement.present is not a function at myComponent.ngAfterViewInit

My Component code snippet: export class MyComponent { //reference to modal (a UI component of external library) @ViewChild('modal') public modal: ElementRef; constructor(private zone: NgZone) {} ...
sandeep ghansiala's user avatar
0 votes
1 answer
59 views

In angular test I type the command ng test, but nothing happens

I am using angular 15.2.5 and am trying to run karma unittests. When I type ng test, the output is: One or more browsers which are configured in the project's Browserslist configuration will be ...
Horst Meier's user avatar
1 vote
1 answer
26 views

Angular unit test with different response from http response

Hi everyone I am almost new in Angular and I want to create fail and success scenario for AUTH service code like below but somehow my success scenario unit test not pass. isAuthenticated(): ...
Afshin's user avatar
  • 4,207
0 votes
0 answers
35 views

ng test in angular throws errors from the node_modules folder?

We have an application that has been in production for years using Angular. When we first started using Angular about 6 or so years ago we did not use any of the karma/jasmine testing tools. In fact ...
Nayrb's user avatar
  • 1,003
-1 votes
1 answer
30 views

Not able to test subscribe method in angular

My ts file has a subscribe method in ngAfterViewInit() which is added below. So while writing test case and doing debugging its not coming inside subscribe method and setting that mock data. So for ...
chopss's user avatar
  • 791
0 votes
1 answer
42 views

Unable to change spy returnValue in Jasmine tests

I'm having a hard time understanding why I'm unable to change the return value of a mock service function using and.returnValue() as mentioned in the Jasmine docs. I've simplified my test file to ...
Robert's user avatar
  • 399
0 votes
0 answers
16 views

Angular E2E Protractor testing : error to join API from testing session

For an Angular application, I'm creating E2E Tests from Protractor and Jasmine. All feel good except the externals API calls. For example, if I try to test and simulate login, the form will correctly ...
Gati's user avatar
  • 5
0 votes
0 answers
35 views

Karma failing with CI/CD in Github

Karma is used to run unit test cases in one of my Angular applications. If you run it locally with the configuration shown below, there are no problems, however if you use CI/CD, you are now seeing ...
Roy's user avatar
  • 890
1 vote
1 answer
480 views

mat-chip-grid must be used in combination with matChipInputFor

I am getting this error while running angular test cases in angular15 version, can anyone help me to resolve this error. This is my code <mat-chip-grid > <mat-chip-row highlighted *ngFor=&...
Sneha's user avatar
  • 91
0 votes
0 answers
49 views

How to fix Eslint error no-unsafe-call on expect Jasmine function on Angular generated spec file?

Angular generates (ng generate service a) spec files with the following content: import { TestBed } from '@angular/core/testing'; import { AService } from './a.service'; describe('AService', () =>...
y.luis.rojo's user avatar
  • 1,804
1 vote
0 answers
30 views

Is there a way to detect unused Angular template?

My goal is to check if HousingListComponent or app-housing-list template is used or not. The problem is when I comment <app-housing-list> in the app.component.html, linter do not tell me that I ...
Jason Rich Darmawan's user avatar

1
2 3 4 5
132