Integration tests in Angular application

Issue I am a bit confused about this test: describe(‘#getUsers’, () => { it(‘should return an Observable<User[]>’, () => { const dummyUsers: User[] = [ new User(0, ‘John’), new User(1, ‘Doe’) ]; service.getUsers().subscribe(users => { expect(users.length).toBe(2); expect(users).toEqual(dummyUsers); }); const req

Continue reading

Angular Material components fail tests

Issue I have a Sidenav Menu made in Angular. The component looks like this: The template: <mat-toolbar color=”primary” [fxLayoutAlign]=”(settings.menuType != ‘mini’) ? ‘space-between center’ : ‘center center'” class=”sidenav-header”> <a mat-raised-button color=”accent” routerLink=”/” (click)=”closeSubMenus()” class=”small-logo”>Menu</a> <a *ngIf=”settings.menuType == ‘default'” class=”logo” routerLink=”/”

Continue reading

unit testing of many simple *ngIf

Issue I have simply component @Component({ selector: ‘app-certificate-panel’, templateUrl: ‘./certificate.component.html’ }) export class CertificateComponent { @Input() public certificate: Certificate; } with template <h3 translate>General</h3> <x-form-row label=”{{‘Version’ | translate}}”> {{ certificate.version }} </x-form-row> <x-form-row label=”{{‘Serial Number’ | translate}}”> {{ certificate.serialNumber }}

Continue reading

Angular – Testing Routerguard

Issue I’m currently struggling on unit testing my canActivate() method from my Routerguard Service. The Service looks as follows: import {Injectable} from ‘@angular/core’; import {ActivatedRouteSnapshot, CanActivate, Router} from ‘@angular/router’; import {AuthService} from ‘../../auth/auth.service’; import {Observable, of} from ‘rxjs’; import {NotificationService}

Continue reading

spyOn not able to spy on the method of a dependent service

Issue I am testing AuthService which sends user login info to server using another HelperService. public authServiceSigninUser(user:UserSigninInfo):any{ console.log(‘In authServiceSigninUser. contacting server at ‘+this.API_URL +this.SIGNIN_USER_URL +” with user data “+user+ ” with httpOptions “+httpOptions.withCredentials + “,”+httpOptions.headers ); //TODOM password should be

Continue reading

unable to mock HttpClient in Jasmine and Karma using HttpTestController

Issue I am testing AuthService which sends user login info to server using another HelperService. public authServiceSigninUser(user:UserSigninInfo):any{ console.log(‘In authServiceSigninUser. contacting server at ‘+this.API_URL +this.SIGNIN_USER_URL +” with user data “+user+ ” with httpOptions “+httpOptions.withCredentials + “,”+httpOptions.headers ); //TODOM password should be

Continue reading

how to unit test subscription to a BehaviourSubject in angular

Issue I have a UserManagementService which exposes an Observable of a BehaviourSubject. this.userSignInState$ = this.signInStateSubject.asObservable(); I subscribe to userSignInState in a nav component. constructor(public userManagementService: UserManagementService, private fb:FormBuilder, private helper:HelperService) { this.userSignInStateSubscription = this.userManagementService.userSignInState$.subscribe( (result:Result)=> { console.log(“In nav – result

Continue reading

rxjs-marbles testing has no expectations

Issue I use rxjs-marbles for testing observables in my Angular 7 app. But it looks like m.expect is not recognized by jasmine as expectation. I have following test: it(‘should see expectations’, marbles(m => { const source: Observable<Message> = m.hot(‘^a–b–c’); m.expect(source).toBeObservable(‘-a–b–c’);

Continue reading

RouterTestingModule not providing provider for Location

Issue I am unit-testing a Component which uses two other components. The other components are created when button is clicked .html <div id=”homepage-top-div” class=”homepage-component-css-grid-container”> … <button id=”get-question-list-button” [routerLink]=”questionListRouterLink” class=”btn content-div__button–blue css-grid-item-button-div btn-sm”>See Questions</button> </div> <div id=”practice-component-top-div” class=”css-grid-container-div common-styles-div–white”> <!– 4

Continue reading

Protractor test in Angular 6 for login screen

Issue I am new in the Protractor testing for Angular 6 application. I am trying to write the spec test for login page as below. describe(‘Protractor Login checing ‘, function() { it(‘should add one and two’, function() { browser.get(‘http://localhost:4041/login’); element(by.model(‘username’)).sendKeys(‘admin’);

Continue reading

Angular 8 Test – Devextreme Grid Child Nodes not Found

Issue I want to test a Devextreme Grid with Angular 8. Here is what my setup roughly looks like: HTML <dx-data-grid id=”grid” [dataSource]=”data”> <dxo-state-storing [enabled]=”true” type=”localStorage” storageKey=”storage-key”></dxo-state-storing> <dxi-column dataField=”field1″></dxi-column> <dxi-column dataField=”field2″></dxi-column> </dx-data-grid> Test describe(‘MyComponent’, () => { let component: MyComponent;

Continue reading

Directive unit testing fails

Issue I am using jest.js for testing with my angular app. here is the directive I use in html: <textarea errorHighlighter formControlName=”Url” name=”Url” cols=”50″ rows=”5″ placeholder=”Enter Page URL” (ngModelChange)=”pageUrlChanges($event)”></textarea> here is my directive.ts file: import { Directive, ElementRef, SimpleChanges, HostListener,

Continue reading

spyOn not working on a dependency in Angular 7 unit tests

Issue I have a component that depends on SearchAttributeService. There is a method called searchAttributeValidation service that returns a Subject. I am subscribing to that subject like this: attributeSearchValidation(): void { this._searchAttributeService.searchAttributeValidation.subscribe((value: string) => { if (value === this._searchAttributeService.emptyAttributeSearchData) {

Continue reading

Angular ngrx test with jest throw error ` console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29`

Issue I do the testing for my ngrx/store with jestjs. i got the testing passing result. eventhough getting an error like: console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29 Error: Cross origin http://localhost forbidden at dispatchError (C:\722333\USD\Project\AOS.UI\NG-USD\node_modules\jsdom\lib\jsdom\living\xhr-utils.js:60:19) at Object.validCORSHeaders (C:\722333\USD\Project\AOS.UI\NG-USD\node_modules\jsdom\lib\jsdom\living\xhr-utils.js:72:5) at receiveResponse (C:\722333\USD\Project\AOS.UI\NG-USD\node_modules\jsdom\lib\jsdom\living\xmlhttprequest.js:842:21) at Request.<anonymous> (C:\722333\USD\Project\AOS.UI\NG-USD\node_modules\jsdom\lib\jsdom\living\xmlhttprequest.js:677:38)

Continue reading