Error: Timed out waiting for Protractor to synchronize with the page after 11001ms." when user browser.getCurrentUrl()

Issue I am testing login and logout functionality, below is my test cases it(‘should redirect to login page on click of logout’,function(){ signInPage.email.sendKeys(‘zahid.afaque@meltwater.com’); signInPage.password.sendKeys(1234); signInPage.loginButton.click(); expect(browser.getCurrentUrl()).toMatch(/\/collections/); signInPage.profileImage.click(); signInPage.logout.click(); browser.waitForAngular(); expect(browser.getCurrentUrl()).toMatch(/\/login/); }); When i run above test its failing and below

Continue reading

Jasmine: Expect does not get actual value

Issue This is second part of: Expect: does not get the actual value I was able to reproduce it a little bit better, so what I have: expect((rfpPage.buttons.sendRequest).getAttribute(‘disabled’)).toBe(‘true’); (rfpPage.inputs.firstName).sendKeys(‘Name’); (rfpPage.inputs.lastName).sendKeys(‘Surname’); (rfpPage.inputs.email).sendKeys(‘name@email.com’); (rfpPage.inputs.phone).sendKeys(‘1234312’); (rfpPage.inputs.company).sendKeys(‘Company’); (rfpPage.inputs.address).sendKeys(‘Leningrad Motorway’); (rfpPage.inputs.city).sendKeys(‘Moscow’); (rfpPage.inputs.postalCode).sendKeys(‘125171’); (rfpPage.inputs.eventName).sendKeys(‘Test Meeting’); expect((rfpPage.buttons.sendRequest).getAttribute(‘disabled’)).toBe(null);

Continue reading

How to mock angular.module('myModule', []).value() in Jasmine/Protractor

Issue I’m trying to use Protractor’s addMockModule() to mock a simple AngularJS module and override a variable: Here is my HTML: <body ng-app=”myApp”> <div ng-controller=”myAppController”> Overriden module value <b>{{myValue}}</b> </div> <script src=”/Scripts/Lib/angular/angular.js”></script> <script src=”/module.js”></script> <script src=”/controller.js”></script> </body> Here is my

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 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

Error in angular unit test cases: TypeError: this.userService.currentUser.subscribe is not a function

Issue I am getting this error while running angular unit test cases: Test Result SidebarComponent × should create TypeError: this.userService.currentUser.subscribe is not a function sidebar.component.spec.ts describe(‘SidebarComponent’, () => { let fixture: ComponentFixture<SidebarComponent>; let mockUserService; beforeEach(() => { mockUserService = jasmine.createSpyObj([‘currentUser’]);

Continue reading

Angular Jasmine spy not being called

Issue I’m following the official Angular tutorial to test a component that calls an asynchronous service function: https://angular.io/guide/testing#component-with-async-service Creating the spy: const gardenSpy = jasmine.createSpyObj(‘GardenService’, [‘getGardens’, ‘createGarden’]); gardenSpy.getGardens.and.returnValue(of(testGardens)); … gardenServiceSpy = TestBed.get(GardenService); Configuring the TestBed to use my spy instead

Continue reading

How to test pending flag in Angular

Issue I have fetchBooks method that retrieve data from backend and then populates books variable. import { Component, OnInit } from "@angular/core"; @Component({ selector: "app-root", templateUrl: "./app.component.html", }) export class AppComponent implements OnInit { isLoading: boolean; books; constructor(private booksService: BooksService)

Continue reading

Initial value is stored in the variable after calling Angular Component method in Jasmine

Issue I have a component as follows: // customer-reservation.component.ts import {Component} from "@angular/core"; @Component({ selector: ‘app-customer-reservation’, template: “ }) export class CustomerReservationComponent { customerCount = 10; registerCustomer() { return this.customerCount++; } unregisterCustomer() { return this.customerCount–; } } Following is specs

Continue reading

Angular unit testing functions

Issue I have just started exploring unit testing in angular. I have a function in .ts file onValueChange(val: number): void { this.formGroup.get(this.controlName).setValue(val); } I am trying to test if the controlName has the value passed in the onValueChange parameters I

Continue reading

Angular testing DOM elements with *ngIf

Issue Why does this test pass it (‘should hide datatable if data is undefined’, () => { component.DATA = undefined; fixture.detectChanges(); expect(fixture.debugElement.query(By.css(‘app-datatable’))).toBeNull(); }); but this doesn’t it (‘should hide datatable if data is undefined’, () => { component.DATA = undefined;

Continue reading

Make test case for reusable mat table columns in jasmine

Issue This is my parent TS import { Component, Input, OnInit } from ‘@angular/core’; import { Column } from ‘../../../../shared/molecules/table/column’; import { DataRecord, TransitReport, } from ‘../../../organisms/transit-report-wrapper/transit-report.model’; @Component({ selector: ‘app-transit-report’, templateUrl: ‘./transit-report.component.html’, styleUrls: [‘./transit-report.component.scss’], }) export class TransitReportComponent implements OnInit

Continue reading

Angular how to test service methods?

Issue I’m trying to learn how to write tests. I don’t understand how to mock and test methods from services. My current service file is the following: import {Injectable} from ‘@angular/core’; import {HttpClient, HttpErrorResponse} from ‘@angular/common/http’; import {Observable, throwError} from

Continue reading

Expect object length to be null

Issue I have the following Object where I need to test it to be null: getLastTeamUpdatedItemLogBuffer(): IBufferElement { const storageItems = this.storageSvc.getItem(StorageKey.lastTeamUpdatedItem, true) as IBufferElement; return storageItems || null; } Here is IbufferElement: export interface IBufferElement { timestamp: number; text:

Continue reading

How to test private field in subscribe of dispatcher in Angular?

Issue I have file: @Component({ selector: ‘page’, templateUrl: ‘./page.html’, styleUrls: [‘./page.scss’] }) export class PageComponent implements OnInit, OnDestroy { private lts: Igst; constructor( private router: Router, private route: ActivatedRoute, private dispatcher: Dispatcher ) { this.dispatcher .ofType(ProductsPageActions.TILE_UPDATE_STATE) .pipe( map((action: ProductsPageActions.St) =>

Continue reading

karma/jasmine/angular toHaveBeenCalledWith is really called

Issue in my app for instance I’ve got $rootScope.$emit(‘loggedin’,data.user); $rootScope.$on(‘loggedin’, function(event,user) { console.log(‘called’); }); in my test spyOn($rootScope, ‘$emit’); var response = { “success”:1, “user”:{ “id”:1, “email”:”lama@test.test”, “fullname”:”Lama user”, “username”:”lamauser”, “groups”:[“Users”] }, “logged”:1 }; $httpBackend.when(‘POST’, ‘/api/v1/user’).respond(200,response); $scope.save(); $httpBackend.flush(); expect($scope.errors.length).toEqual(0); expect($rootScope.$emit).toHaveBeenCalledWith(‘loggedin’,response.user);

Continue reading

How to mock socket.io with Angular and Jasmine

Issue I’m having trouble figuring out how to correctly mock Socket.io in an Angular application using Jasmine and Karma. Here are the files found in karma.conf.js: ‘bower_components/angular/angular.js’, ‘bower_components/angular-mocks/angular-mocks.js’, ‘bower_components/angular-ui-router/release/angular-ui-router.js’, ‘bower_components/angular-socket-io/socket.js’, ‘bower_components/socket.io-client/socket.io.js’, ‘bower_components/angular-socket-io/mock/socket-io.js’, ‘public/javascripts/*.js’, ‘ng_tests/**/*.js’, ‘ng_tests/stateMock.js’ Here is how my controller

Continue reading

Jasmine/Angular: TypeError: Cannot read property '$modules/$injector' of undefined

Issue I am trying to run jasmine test cases and i am landing on ‘$modules’ of undefined. I am loading unminified and latest versions of libraries as below, <script src=”lib/jquery-2.1.3.js”></script> <script src=”lib/jasmine-2.1.3.js”></script> <script src=”lib/jasmine-html.js”></script> <script src=”lib/boot.js”></script> <script src=”lib/angular-1.3.9.js”></script> <script src=”lib/angular-mocks-1.0.1.js”></script>

Continue reading

Jasmine – Testing if Controller Exists Getting Error

Issue i have a simple controller: app.controller(“RegisterController”, function ($scope, $location) { // Do something }); And all i am trying to do is to test this controller is defined: describe(‘RegisterController’, function() { var $rootScope, $scope, $controller; beforeEach(module(‘myApp’)); beforeEach(inject(function(_$rootScope_, _$controller_){ $rootScope

Continue reading

AngularJS and Jasmine: mocking services

Issue I am having trouble mocking the dependency of the following service “broadcaster” over the service “pushServices”. angular.module(‘broadcaster’, [‘pushServices’]); angular.module(‘broadcaster’).service(‘broadcaster’, [ ‘$rootScope’, ‘$log’, ‘satnetPush’, function ($rootScope, $log, satnetPush) { // .. contents .. }; }; The Jasmine spec is as

Continue reading