Questions tagged karma-jasmine

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

Jasmine Karma fails with ‘ReferenceError: process is not defined’

I recently updated from Angular9 to Angular 12. After the update my tests have started "failing". I have quotes around that because the tests themselves seems to be fine, however after every run there is an "Error" entry that is not very helpful Uncaught ReferenceError: process is not defined ReferenceError: process is not defined at […]

By kewur
Published
Categorized as angular, karma-jasmine, karma-webpack Tagged , ,

Uncaught TypeError: Cannot read properties of undefined (reading ‘toLowerCase’) thrown

I have this error "Uncaught TypeError: Cannot read properties of undefined (reading ‘toLowerCase’) thrown". My code in jasmine: describe(‘Send()’, () => { it(‘should return a promise’, async (done) => { let data = { action: ‘get’, component: ‘/filter’, } service.send(data.component, data.action, null).then((res) => { console.log(res); done(); }); }); }); My function in typescript: send = […]

By David Angarita
Published
Categorized as angular, karma-jasmine, typescript Tagged , ,

Unit test a return methods output value

I have a method that a string enters, its transforms then returns a new string value. I have tried numerous ways to get it to test correctly, as you can see below there are a few lines commented out… spec.ts const string = "testing%20this.jpg"; //input const sanitisedString = "testing this"; //expected output it(‘should sanitiseString’, () […]

How to test a function that returns a promise and a obsevable?

I have this function in typescript: send = (component: string, action: string, payload: object = null) => { var data = { ‘action’: action, ‘component’: component }; if (payload !== null) { data = Object.assign(data, payload); } return new Promise((resolve, error) => { this.http.post<any>(this.APIURL, data).subscribe(res => { if (res.success) { resolve(res.data); } else { console.error(res); […]

By David Angarita
Published
Categorized as angular, karma-jasmine, typescript Tagged , ,

How can I test this function in Jasmine Angular

I have this function with typescript in angular: send = (component: string, action: string, payload: object = null) => { var data = { ‘action’: action, ‘component’: component }; if (payload !== null) { data = Object.assign(data, payload); } return new Promise((resolve, error) => { this.http.post<any>(this.APIURL, data).subscribe(res => { if (res.success) { resolve(res.data); } else […]

By David Angarita
Published
Categorized as angular, karma-jasmine, typescript Tagged , ,

How can to test this funcion in Jasmine this function?

I have this function with typescript in angular: send = (component: string, action: string, payload: object = null) => { var data = { ‘action’: action, ‘component’: component }; if (payload !== null) { data = Object.assign(data, payload); } return new Promise((resolve, error) => { this.http.post<any>(this.APIURL, data).subscribe(res => { if (res.success) { resolve(res.data); } else […]

By David Angarita
Published
Categorized as angular, karma-jasmine, typescript Tagged , ,

Inconsistency jasmine test with tick and auditTime

After check several posts I can’t find a solution to the issue I’m faced of. I have a form which is saved each 2 seconds in database if a value changes. So in the app.ts looks like this: ngAfterViewInit() { this.form.valueChanges .pipe( auditTime(2000), distinctUntilChanged(…), concatMap(() => { return this.saveform(); }) ) .subscribe(…); And to test […]

By sha
Published
Categorized as angular, jasmine, karma-jasmine, unit-testing Tagged , , ,

Angular 11 – Test case writing – Jasmine – deprecation issue

I’m trying to create my very first test case using Jasmine and its my first attempt in writing test cases(actually just started learning). I’m currently referring This site to write test case Here I’m facing two issues. The signature ‘(token: any, notFoundValue?: any): any’ of ‘TestBed.get’ is deprecated.ts(6387) testing.d.ts(382, 9): The declaration was marked as […]

How solve the undefined value in jest angular unit testing?

I have passed the api response value from one function to another function, But in JEST unit test case showing undefined, How to solve this error this.passvalue(this.content.name); I got the below error TypeError: Cannot read property ‘name’ of undefined 27 | 28 | 29 | this.passvalue(this.content.name); | ^ 30 | } 31 | passvalue(name="" ){ […]

Error: Unexpected value ‘CookieService’ imported by the module ‘DynamicTestModule’. Please add an @NgModule annotation

I’m trying to test a service with jasmine but i have this error: Error: Unexpected value ‘CookieService’ imported by the module ‘DynamicTestModule’. Please add an @NgModule annotation. and Error: Expected undefined to be truthy. My spec file: import { RouterTestingModule } from ‘@angular/router/testing’; import { TestBed } from ‘@angular/core/testing’; import { Api } from ‘./api.service’; […]

By David Angarita
Published
Categorized as angular, karma-jasmine, typescript Tagged , ,
1 2 3 75

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
faq