Questions tagged unit-testing

Explore the latest questions and answers asked by our top developers.

Angular unit testing a function variable

I want to test a variable function of a void function. How can I get that local variable in the test? function: save(){ const stringTest="test"; } test: test("variable should be equal to "test" ", () => {; //test stringTest from save function that is equal to "test" }); Source: Angular Questions

By denisiulian
Categorized as angular, testing, typescript, unit-testing Tagged , , ,

test cases for angularFire multiple time App initialization issues

I am writing test cases for my Angular-Ionic PWA. with latest version of AngularFire that is "@angular/fire": "^7.0.4", Component1.spec.ts import { provideFirebaseApp, initializeApp } from ‘@angular/fire/app’; import { getFunctions, provideFunctions } from ‘@angular/fire/functions’; import { getFirestore, provideFirestore, enableMultiTabIndexedDbPersistence } from ‘@angular/fire/firestore’; import { getDatabase, provideDatabase } from ‘@angular/fire/database’; import { getStorage, provideStorage } from ‘@angular/fire/storage’; […]

Angular UnitTesting is not working for custom Validators

I was trying to create a .Spec file for my validator file but I’m getting the below error while testing the validators file. Erros Error: Can’t Resolve all parameters for function (testFormGroup) {:(?) Please see the below my code and is there any possibilities to make this run. HTML <div [formGroup] = "testFromGroup"> <input type="text" […]

Property recognized as undefined in spec file even though it exist in the component. Unit Test in Angular with Karma – Jasmine

I have the following method in a component in Angular but when I wrote the unit test for it, it fails, does not recognize properties that actually exists in the component; this is my method makeUrl(): string { const base: string = this.marketConditionsEnvironment.apiRoot; const tempEquipment: string = ‘?equipment=Van’; const origin: string = this.makeLocation(‘origin’, this.marketConditionsData.origin); const […]

How do I test a component injected with a service and then use that service to simulate its behavior in Angular

I have two unrelated component that communicated with each other via a service. I want to test the behavior of one the components. I know I have to either mock or sub the service but I am not sure which one should I do ? and If I am doing things correctly comp1.ts: export class […]

By S A
Categorized as angularjs, testing, unit-testing, web Tagged , , ,

Unable to test MatTable filling rows with Karma test

I would like to be helped in understanding what’s wrong with my code approach. I tried to mimic the dynamics of this tutorial about Harnesses I have the following Angular component, which is a straightfoward data table (MatTable) bound to a remote service. Instead of GoT characters, it works with system roles as part of […]

By usr-local-
Categorized as angular, karma-jasmine, unit-testing Tagged , ,

Does Angular’s DestroyAfterEach option affect the speed of Jest tests?

DestroyAfterEach is a new option that was added in Angular 12.1, and promises to greatly speed up test performance (details here). However, when making this change, I am not noticing any speed difference. I suspect this may be because I’m using Jest, which does not involve a browser. Is it expected that Jest does not […]

By Benjamin Kindle
Categorized as angular, angular12, jestjs, unit-testing Tagged , , ,

Angular Testing: How can i call expectations after a function got executetd

i am currently unittesting my application in angular and got the problem that i need to use a http call on a local file. Therefore the expect’s of the test got called before and after the http call so it crashes. How can i fix that problem? I am currently trying to call the expect’s […]

By dominikW
Categorized as angular, http, karma-jasmine, unit-testing Tagged , , ,

How can you determine how to reference a path to a local configuration file while running npm test?

I need to figure out what the path is to /dev-app/assets/configuration/ in order to write some unit tests against a real-world, large YAML file to validate it. dev-app is a web app that references the various libs (see image), so when the app actually utilizes the libs they have ./ as the root path to […]

By 333Matt
Categorized as angular, karma-jasmine, unit-testing Tagged , ,

unit test angular ngrx component

I’m trying to test a unit test for a component into angular, into the component I have a filterTypeahead function that expect a string, this value is inserted into a Subject, when it happen I have other code for dispatch a loadData, so with filteredData$ observable I subscribe to it for get the data it(‘should […]

By Yoedusvany Hdez
Categorized as angular, javascript, unit-testing Tagged , ,
1 77

Still Have Questions?

Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us