karma-jasmine

Error: Expected one matching request for criteria “Match by function: ”, found none

戏子无情 提交于 2020-08-07 05:44:59
问题 I have a userService.spec.ts file that I want to test.The code goes this way. It calls a get function that calls the ADMIN_API_URL .I tried testing the given file but got an error that is mentioned in the title. My user.service.spec.ts file. describe('Service: User service', () => { let httpMock: HttpTestingController; let userService: UserService; let url: string; beforeEach(() => { TestBed.configureTestingModule({ imports: [HttpClientTestingModule], providers: [ { provide: AUTH_API_URL,

Angular 9 - Istanbul test coverage report being generated empty

醉酒当歌 提交于 2020-08-05 15:23:46
问题 I'm getting an empty report, it's listing the files but it's not filling up the percentages... Any idea on what can be causing it? Error message: Handlebars: Access has been denied to resolve the property "statements" because it is not an "own property" of its parent. My package.json file: "dependencies": { "@angular/animations": "^9.0.4", "@angular/cdk": "^9.1.0", "@angular/common": "^9.0.4", "@angular/compiler": "^9.0.4", "@angular/core": "^9.0.4", "@angular/forms": "^9.0.4", "@angular

Angular 9 - Istanbul test coverage report being generated empty

一个人想着一个人 提交于 2020-08-05 15:23:34
问题 I'm getting an empty report, it's listing the files but it's not filling up the percentages... Any idea on what can be causing it? Error message: Handlebars: Access has been denied to resolve the property "statements" because it is not an "own property" of its parent. My package.json file: "dependencies": { "@angular/animations": "^9.0.4", "@angular/cdk": "^9.1.0", "@angular/common": "^9.0.4", "@angular/compiler": "^9.0.4", "@angular/core": "^9.0.4", "@angular/forms": "^9.0.4", "@angular

How can i simulate browser focus when testing using angular and jasmine?

蹲街弑〆低调 提交于 2020-08-01 11:27:13
问题 I am trying to write a unit test that checks whether or not the effect of a focus event takes place. My actual test case is more complicated, but I have created a minimal reproduction with the following code: it('testing input focus', async(() => { let showDiv = false; const template = `<div *ngIf="shouldShow" class='hidden-div'> SHOW ME WHAT YOU GOT </div> <input (focus)="shouldShow = !shouldShow" name="input">`; buildTestComponent(template, {shouldShow: showDiv}).then((fixture) => { fixture

Karma - ChangeDetectorRef detectChanges mocking

萝らか妹 提交于 2020-07-09 04:14:26
问题 I have an issue with cdr.detectChanges() in my test. I have an error happening when it's called and I don't have any information, I just get this error : ZoneAwareError@webpack:///~/zone.js/dist/zone.js:923:0 <- config/karma-shim.js:108645:28 invokeTask@webpack:///~/zone.js/dist/zone.js:398:0 <- config/karma-shim.js:108120:36 onInvokeTask@webpack:///~/zone.js/dist/proxy.js:103:0 <- config/karma-shim.js:107642:49 Is there a way to make detectChanges work? I also tried something else by trying

How to do jasmine unit test case for angular 6 bootstrap 4 modal

浪子不回头ぞ 提交于 2020-07-07 07:38:06
问题 html <ng-template #content let-modal> <h1>Modal content inside this ng-template #content </h1> </ng-template> Button to open model <button (click)="open(content)" > Open modal </button> In ts file import { NgbModal, ModalDismissReasons } from '@ng-bootstrap/ng-bootstrap'; constructor( public modalService: NgbModal) { } open(content) { this.modalService.open(content, { ariaLabelledBy: 'modal-basic-title', size: 'lg' }).result.then((result) => { this.closeResult = `Closed with: ${result}`; },

Angular 7 : ng test hangs , keeps running tests repeatedly

我只是一个虾纸丫 提交于 2020-07-06 08:59:14
问题 i ve recently migrated my Angular 6 app to Angular 7 my package.json looks like this : { "name": "myApp", "version": "3.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve --public-host http://localhost:4200/", "build": "ng build --prod", "serve": "ng serve --optimization=true --source-map=true --eval-source-map=true --live-reload=true --aot=false --vendor-chunk=true", "build-prod": "node --max_old_space_size=5000 ./node_modules/.bin/ng build --configuration=production",

Angular 7 : ng test hangs , keeps running tests repeatedly

孤街浪徒 提交于 2020-07-06 08:57:32
问题 i ve recently migrated my Angular 6 app to Angular 7 my package.json looks like this : { "name": "myApp", "version": "3.0.0", "license": "MIT", "scripts": { "ng": "ng", "start": "ng serve --public-host http://localhost:4200/", "build": "ng build --prod", "serve": "ng serve --optimization=true --source-map=true --eval-source-map=true --live-reload=true --aot=false --vendor-chunk=true", "build-prod": "node --max_old_space_size=5000 ./node_modules/.bin/ng build --configuration=production",

How to test a JSONP method in a service - Angular

≯℡__Kan透↙ 提交于 2020-06-13 07:00:37
问题 I am making a simple email subscription application for which I have written tests and things went fine as for now. In order to make things simple, I wish to explain the exact part where I am facing the issue. my-service.ts : export class MyService { mailChimpEndpoint = 'https://gmail.us10.list-manage.com/subscribe/post-json?u=aaa7182511d7bd278fb9d510d&id=01681f1b55&amp'; constructor(private _http: HttpClient) {} submitForm(email: string){ const params = new HttpParams() .set('EMAIL', email)

How to cover the test for form control in angular? (Stackblitz attached)

空扰寡人 提交于 2020-06-13 05:59:06
问题 I am making a simple application which has an input field and a button and on click of the button an api call was made and respective response is fetched. Everything working fine with this. Things done as of now: I am making a validation and display the error message via a function like, hello.component.ts : controlErrors(formControl: AbstractControl | FormControl): string { if ( formControl && formControl.touched && formControl.invalid && formControl.errors ) { return Object.keys(formControl