karma-jasmine

Webpack directory appended at error after migrating to Angular9

雨燕双飞 提交于 2020-06-13 05:28:26
问题 I've recently upgraded my projet from angular 7 to angular 9. When I run the tests ( ng test ), I always get http://localhost:9876/_karma_webpack_/ appendend to the error, hence in visual studio code, we can't click on the error to got directly to the file. For the sake of testing, I've added expect(2).toEqual(1); in the app.component.spec.ts file For example, with the angular 7 projet out of the box, I get this error with ng test: Chrome 81.0.4044 (Windows 10.0.0) AppComponent should have as

Angular Unit Test: Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'logout'

醉酒当歌 提交于 2020-06-13 04:53:03
问题 I am always getting this error randomly for differennt tests when I enable my login.spec.ts tests. Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'logout' I tried to fake the logout method in authService using: spyOn(authService, 'logout').and.returnValues(true); But still it doesnt work. Please help figuring out the issue here. login.component.ts export class LoginComponent implements OnInit { isLoggingIn = false; constructor( private authService:

Angular Unit Test: Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'logout'

心不动则不痛 提交于 2020-06-13 04:52:47
问题 I am always getting this error randomly for differennt tests when I enable my login.spec.ts tests. Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'logout' I tried to fake the logout method in authService using: spyOn(authService, 'logout').and.returnValues(true); But still it doesnt work. Please help figuring out the issue here. login.component.ts export class LoginComponent implements OnInit { isLoggingIn = false; constructor( private authService:

Angular Unit Test: Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'logout'

元气小坏坏 提交于 2020-06-13 04:52:20
问题 I am always getting this error randomly for differennt tests when I enable my login.spec.ts tests. Uncaught Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'logout' I tried to fake the logout method in authService using: spyOn(authService, 'logout').and.returnValues(true); But still it doesnt work. Please help figuring out the issue here. login.component.ts export class LoginComponent implements OnInit { isLoggingIn = false; constructor( private authService:

How to unit test return value of function - Angular (Jasmine/Karma)

試著忘記壹切 提交于 2020-06-12 04:54:57
问题 I am wondering if there is a way to correctly test the return value of a function in Angular. I want to essentially test the return value to be true for one test and write another to test the opposite scenario. Ts component: get() { if (this.object == undefined) { return true; } else { return false; } } The only way I can see fit right now to test the return value is to set a variable to hold the return value. Below is my attempt, I'm just stuck on asserting what is to be expected. Test: it(

How to cover test for button click in angular? (Stackblitz attached)

狂风中的少年 提交于 2020-06-11 07:42:53
问题 I am making a very simple application which has one input box and a button. Input is for entering email Subscribe button with event handler Entering email and click over the button will make an api call, (This method works) subscribeEmail() { this.error = ''; if (this.userForm.controls.email.status === 'VALID') { const params = new HttpParams() .set('EMAIL', this.userForm.controls.email.value) .set('subscribe','Subscribe') .set('b_aaa7182511d7bd278fb9d510d_01681f1b55','') console.log(params);

Code Coverage report shown only for polyfills.ts and test.ts under Dev\ folder. Doest show coverage for files under src folder

你说的曾经没有我的故事 提交于 2020-06-09 07:08:06
问题 In my angular 7 app, when i run "ng test --watch=false --code-coverage true" i get the coverage report in my coverage folder, but coverage is shown only for two files. (Polyfills.ts & test.ts). Below is my project structure. Please let me know how to get coverage for files under SRC folder. Note: when i run ng test all the tests under SRC folder is getting executed. dev --app --test.ts --tsconfig.app.json --tsconfig.spec.json src --lib --component --services angular.json karma.conf.json test

Callback and Testing Highcharts

故事扮演 提交于 2020-06-06 08:18:49
问题 I am currently using angular 9 with Highcharts. Link to the code : https://stackblitz.com/edit/angular-ivy-wdejxk Some instructions for running on application-side / test-side : Test - side : inside angular.json file on line number 18, change "main": "src/main.ts", to "main": "src/main-testing.ts", and do a refresh of the browser. Application - side : Change exactly the opposite of previous. "main": "src/main-testing.ts", to "main": "src/main.ts", Here are a few issues i am stuck upon : I

Angular testing - observable pipe is not a function

回眸只為那壹抹淺笑 提交于 2020-05-30 07:13:42
问题 I want to write a unit test for a photo-upload-mehtod. But I get the Failed: this.task.snapshotChanges(...).pipe is not a function TypeError: this.task.snapshotChanges(...).pipe is not a function Error. For the sake of simplicity of this question, I put the code all in one method: Component public startUpload(event: FileList) { const file: File = event.item(0); const pathRef = `users/${this.uid}`; this.task = this.service.uploadPhoto(pathRef, file); this.fileRef = this.service

Anuglar 9 unit testing for service for post request?

妖精的绣舞 提交于 2020-05-17 06:23:31
问题 How can i write test case for service in my HomeComponent.spec.ts file. And for proceed button postRequest method called from the home.service.ts file. i have tried out but it's not working. kindly help me out. home.service.ts import { Injectable } from '@angular/core'; import { API_ACTIONS } from 'src/app/global/constant/common-constant'; import { CommonService } from 'src/app/global/services/common.service'; import { environment } from 'src/environments/environment'; @Injectable() export