289 questions
0
votes
2
answers
257
views
Ionic Storage v3 - Unit Tests | TypeError: _this.storage.forEach is not a function
I have a StorageService wrapper for @ionic/storage-angular where I have a function that looks roughly like this:
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage-...
2
votes
2
answers
804
views
Why the angular unit test is not testing the content of the subscription in this service?
I'm using Angular 14. I'm trying to test this service:
import { EnvironmentService } from './environment.service';
import { MsalService, MsalBroadcastService, MSAL_GUARD_CONFIG, MsalGuardConfiguration ...
5
votes
2
answers
3k
views
Typescript opposite / reverse operation of "typeof"
Angular can Query subComponents by Types, which is used in Testing like this:
fixture.debugElement.query( By.directive( ComponentType ) );
Now i wanted to make a function which does this for me:
...
0
votes
1
answer
4k
views
Angular 9 : Karma Coverage : How to display coverage report with only specific files
Background
We have an existing a huge angular application without any unit tests and we have just started writing the test cases. When I run the command
ng test --code-coverage
Problem
I see all the *...
0
votes
0
answers
770
views
How to Handle zone-evergreen.js HTTP 400 Bad Requests in Protractor?
I am writing a test with Angular11/Protractor which fills a registration form and then submits it to the backend server. The test expects that the server will respond with an HTTP 400 Bad Request ...
1
vote
0
answers
1k
views
Angular testing using jest and spectator fails TypeError: testing.waitForAsync is not a function
I am using
Angular CLI: 10.2.3
Node: 12.22.1
npm: 6.14.12
I am new to angular. I am trying to use jest for testing angular code (project runs fine without any errors, now adding some tests where I see ...
2
votes
1
answer
7k
views
How would I mock route queryParams in ngOnInit() in a spec test
Failed: Cannot read property 'queryParams' of null
at
I'm assuming it's because I have the following in ngOnInit():
ngOnInit() {
this.route.queryParams.subscribe(async params => {
this....
1
vote
2
answers
549
views
Unable to run a simple karma test against my angular 4 code
I'm trying to do a bare minimum test on my Angular 4 components, and I can't get it to work at all.
I'm running this command: karma start src/test/javascript/karma.conf.js
And here is the output: ...
1
vote
1
answer
2k
views
How to make the Angular 2 unit tests for Meta tags from the browser-platform library?
I am writing a unit tests for Angular 2 component with Jasmine. I will like to test if my document metatags as been set to a specific value when my component is instantiated.
My component:
import { ...
0
votes
2
answers
730
views
Angular e2e test with Protractor: click intercepted by parent of element selected by id
Sometimes I get this error but not every time I run the test. What is causing this strange behavior?
Failed: element click intercepted: Element <div id="myButton">...</div> is not ...
1
vote
1
answer
888
views
How to test ControllValueAccessor in Angular2
I am writing Karma tests for my angular application. I use custom form controlls that are created with the ControllValueAccessor.
Is there a way to test the implemented ControllValueAccessor methods (...
0
votes
1
answer
3k
views
How to test if statement in ngOnInit that depends on route param
My Angular 8 web app has one component that does different things depending on the route. In ngOnInit I use route data to check if the cached param is present. I am trying to write a unit test that ...
4
votes
1
answer
1k
views
Need to resolve the service dependency error with the component using karma jasmine
My aim is to unit test NewServicesRequestsComponent , I was able to resolve other dependencies but stuck with the service dependency named GenericService
I tried out resolving XHRbackend error by ...
3
votes
1
answer
1k
views
Angular 2+ Service Testing. Service imports are undefined at ng test runtime
I'm new to Angular and attempting to test an Angular 6 service which utilizes handlebars.js to build client-side html templates, based on input JSON / data.
The service produces the desired result in ...
1
vote
1
answer
506
views
angular unit test ngOninit
The testbed config is
TestBed.configureTestingModule({
declarations: [ EditPersorgaComponent, ArrayFromIntPipe, TeamFilterPipe ],
schemas: [ NO_ERRORS_SCHEMA ],
...
0
votes
1
answer
367
views
Unit test fails after adding a new test
I am currently working on an Ionic (v3) app and we have several tests to test services, pages and components.
Everything was working fine until I added a new test for a component.
Both tests run ...
1
vote
3
answers
714
views
Is it possible to list array of component dependency injectors?
How do I list all the dependency injectors of a component in angular?
This requirement is for unit testing.
I have an instance of a component created as follows :
component = fixture....
6
votes
2
answers
7k
views
Angular2 how to Mock Activated Route Params subscribed
I have a components that gets a value from the params property of a ActivatedRoute.
The components looks like:
......
constructor(public userRegistration: UserRegistrationService, public userLogin:...
2
votes
1
answer
5k
views
Angular 5 unit testing: How to make change detection work properly?
How to make change detection in unit tests work properly?
From sources, changeDetection should be ran after microtasks are empty (including event tasks?).
this._onMicrotaskEmptySubscription = ngZone....
2
votes
1
answer
4k
views
Not able to reset providers in beforeEach after creating TestBed once in beforeAll
We writing test case for a component which has many nested services and components (we cannot mock every service for our requirement). We have created module which contains all the components and ...
9
votes
1
answer
9k
views
Angular 2 -Unit Test: How to expect throw new Error("error") from component
I writing unit test for angular 2 by jasmine + karma.
I have the component check exception and throw error. And write unit test to check this case.
But I seen an error message when trigger fixture....
1
vote
0
answers
155
views
test function whenstable of angular2 didn't wait for promise resloves
I'm using SystemJsModuleLoader to load modules, it works just fine.
But when I test my app, whenStable didn't works as it describes.
It resolves so fast that systemjsLoader.load() hasn't resolved yet.
...
1
vote
2
answers
5k
views
Angular2 + Jasmine Event Object
I have this simple method which needs to be tested:
public onLayerContainerClick(event: Event): void {
event.stopPropagation();
event.preventDefault();
if (event.srcElement.classList....
6
votes
2
answers
3k
views
Cannot find name 'viewport'
I am using karma viewport npm package to set the viewport for chrome browser via jasmine test spec. I am following the guidelines from the link provided above. It's quite simple, but somehow I am not ...
47
votes
3
answers
21k
views
Test pipe with dependencies on services
I have a pipe that sanatises HTML as below:
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({
name: 'sanitiseHtml'
})
export ...
3
votes
2
answers
1k
views
Location class from @angular/common doesn't work in unit tests
For some reason Location.normalize() and other functions doesn't return correct response when I run tests:
import { Router } from '@angular/router';
import { Location } from "@angular/common";
import ...
6
votes
0
answers
8k
views
Is the MockBackend way of testing HTTP calls deprecated in Angular4?
I am trying to test the HTTP calls and referring to the following page to write unit tests: https://angular-2-training-book.rangle.io/handout/testing/services/mockbackend.html
But when I looked on ...
2
votes
1
answer
1k
views
Combine toHaveBeenCalledTimes with toBeGreaterThan
Is there a way in jasmine where I can combine toHaveBeenCalledTimes with toBeGreaterThan?
I want to know whether the spy object has called a particular method at least 2 times.
spy Object
spyOn(...
2
votes
1
answer
1k
views
How to write a unit test for observable finally block in jasmine - angular 2
I have a save method.
public saveJob(formData: any, redirect: boolean = false): Observable<any> {
if (!this.checkJobValidity()) {
return Observable.of(null);
}
return this....
0
votes
0
answers
661
views
Angular4 Karma-Jasmine test not running
I am trying to get my Karma-Jasmine tests set-up and can't work-out where I am going wrong.
Can't seem to understand where the problem is and have tried various solutions from online searches have ...
5
votes
2
answers
7k
views
how to get arguments on an event emitter in jasmine test
I have a unit test as below
it('billing information is correct', () => {
fixture.detectChanges();
spyOn(component.myEventEmitter, 'emit').and.callThrough();
component.form.controls['...
1
vote
1
answer
2k
views
Angular 2 Testing: Spying on ngOnInit() in beforeEach?
Context
My issue is that my ngOnInit function calls many sub functions asynchronously by using Firestore to populate a form from one document as well as subscribing to various collections to display ...
6
votes
1
answer
3k
views
why ngForm "controls" property is empty in my test? (Angular)
I have a component which employs template-driven form
<form (ngSubmit)="onSearchCorpus(form)" #form="ngForm">
<combo-box [(ngModel)]="model.corpus" name="corpus" #corpus="ngModel"></...
4
votes
2
answers
2k
views
Not able to change a component's property from unit test
I am trying to write a test to ensure that my method returns the right value based on one of the component's properties.
So in my unit test I want to set the value of the component's properties and ...
2
votes
0
answers
2k
views
jasmine unit test error when adding Cookie Service
while writing jasmine unit test case for one of my angular 2 component, if I add CookieService in provider list then all remaining other component unit test cases are failing. If I remove ...
0
votes
1
answer
949
views
Unable to locate the function in spec file
Example.ts
export class Example{
public async initService(Id): Promise<any> {
//promise logic
}
}
Example.spec.ts
//imported Example class correctly
describe('testing', async () =&...
0
votes
1
answer
1k
views
How can you create a new (xml) file in angular testing
I am working on an unittest in a Angular(2) project.
But I ran into an issue that I can not create a new File for my test.
In my test I have the following code:
const newfile = new Blob(['...
8
votes
3
answers
5k
views
Angular2 - Executing e2e tests in different environments
I am new to Protractor. I have developed few tests cases to accomplish the end to end testing. These test cases works fine in all 3 different environments that we have : dev, testing and production.
...
1
vote
0
answers
612
views
Angular 2 karma unit tests, template error
I've got a problem - when I try to configure testbed, it throws error
Failed: Uncaught (in promise): Failed to load /student-register.component.html
I tried to solve this problem by overriding the ...
0
votes
0
answers
1k
views
How to share TestBed between specs of sibling components in Angular?
I am looking for a way to share the TestBed between different files in Angular spec files. I understand, that I can always write a simple util class to do so, but am not sure if that is the correct ...
0
votes
0
answers
1k
views
Angular2: Unit testing a component with Route resolve
I have a component that depends on a data from Route Resolve.
Following is the code snippet of the router
{
path: 'attachment',
component: ...
2
votes
1
answer
273
views
How to test a Floating Action Button in Ionic2
I have an Ionic2 project, with the Unit Testing setup based on the clicker repository.
I try to use a Floating Action Button in a component but it throws an exception when running the unit tests. I ...
3
votes
1
answer
1k
views
Load all Components and Providers from one source for Angular Unit Tests
I have been learning Angular 2 unit testing for the last month or so and have come across a tedious process that I am trying to figure out how to get around. This tedious process has to do with ...
5
votes
1
answer
3k
views
Angular 2 - Unit test binding to nested custom form control
I've got a custom from control with selector app-date-picker. It implements ControlValueAccessor. I have a component called MyPage that contains this custom form control via:
<app-date-picker ...
2
votes
1
answer
933
views
Not able to click the button using element(by.css()) with protractor on ionic2
I am able to navigate to the page, but on the navigated page I am trying to click the button which is showing error as follows:
× navigates to the next page on click
- Failed: unknown error: Element &...
0
votes
1
answer
877
views
How can I remove the npm error from the protractor's logs when any spec fails?
I have started using the protractor with jasmine on an ionic2 application.I have 2 major doubts that did not gets cleared on searching on web:
1.)When any of my specs fails the tests, the error is ...
0
votes
1
answer
803
views
The value of the JSON array displays undefiend after converting it into string
Part of my service.spec.ts is below:
service.spec.ts
it('should mock the http requests', inject([Service, MockBackend], (service, mockBackend) => {
let result:any;
mockBackend.connections....
0
votes
0
answers
2k
views
Expected undefined to equal 2
Technologies Used: Karma/Jasmine, Angular2
service.ts
Injectable()
export class Service {
constructor(private http: Http) { }
getGoogle(): Observable<any>{
console.log("...
1
vote
1
answer
9k
views
Angular2 Unit Test Mouse Events
I want to test one of methods which helps in closing Modal Window when closed outside of Modal Window container.
Component Method
public hide(): void {
this.visibleAnimate = false;
...
0
votes
1
answer
30
views
Do I need to create a mock/stub to test this asynchronous function?
The function I want to test is asynchronous, This function is present in a class.
Do I need to create a mock/stub to test this function?If yes then how to create one?
delayedAlert(message: string, ...