Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
1 vote
0 answers
200 views

How can i test ng template ref from child component in angular 7

show-data.component.html <responsive [mobile]="mobile" [tablet]="tablet" [desktop]="desktop" ></responsive> <ng-template #mobile> <h1> hello from ...
Pushpak's user avatar
  • 77
3 votes
1 answer
2k views

Angular Unit Test for Singleton Service

I am working on a unit test in angular regarding singleton service. I have a UserService that is provided in the root module is a singleton in the application and I want to write a unit test to check ...
Dev001's user avatar
  • 256
0 votes
1 answer
641 views

Expected spy navigate to have been called with [ [ '/login' ] ] but it was never called

I am writing test case for a below block of code: someFn() { if (this.loginStatus === '1') { this.router.navigate(['/login']); } } In my spec file: import { Router } from '@angular/...
pix1289's user avatar
  • 514
1 vote
2 answers
7k views

how to trigger a subscribe to an event emitter inside a function. Angular unit test

I've been trying to test a function that contains a subscribe of an EventEmitter, the unit test is calling the subscribe but It has been impossible to test the code inside the subscribe, I mean, the ...
RobG's user avatar
  • 23
1 vote
0 answers
1k views

Angular unit test with DOM manipulation

Hi I would like to ask for help to test the function below. My approach is that I will be assigning tr to my tagName in my testcase to test the if conditions inside of it. The function in my TS ...
Eduwow's user avatar
  • 157
-1 votes
1 answer
494 views

Angular 7 Unit testing - PhantomJS has crashed

I am using Angular 7 for unit testing using karma and phantom JS. While I have run from my local machine, from my MAC -- ng test --watch=false Local Machine Output - ng test 10% building modules 2/...
Atique Ahmed's user avatar
0 votes
1 answer
607 views

TypeError: Cannot read property 'nativeElement' of undefined -- in ngAfterViewChecked

Some of my karma jasmine unit tests are failing after I added an ngAfterViewChecked. I am not sure what I am doing wrong here. I tried initializing the below "mySwitchEl" but still got the same error. ...
lzdyzydy's user avatar
0 votes
1 answer
465 views

How to unit test Ionic 3 apps

I would like to unit test my ionic 3 app. I am unable to run below commands npm test, ng test etc. I have installed angular cli also but unbale to run the test commands. Below is my package.json ...
swapnil skate's user avatar
2 votes
0 answers
311 views

How to use Karma Jasmine "toHaveBeenCalledWith" an Array?

I have a unit test like so: it('should be successful', fakeAsync(() => component.doSomething(); let myObj = { abc: 'test1', dfg: 'test2' } let myArray: Array<AnObject> = [...
lzdyzydy's user avatar
2 votes
1 answer
3k views

How to mock Routing state in angular for unit tests

I am writing unit tests for my component but having trouble in creating the instance of the component and showing following error: TypeError: Cannot read property 'patientId' of null I have tried ...
Umer's user avatar
  • 157
0 votes
1 answer
244 views

Angular 7 Testing Karma Error : Can't resolve all parameters for WebStorageService: (?)

WebStorageService works fine in component , but when trying to test in Karma gives below exception. Error: Can't resolve all parameters for WebStorageService: (?). Below My Specs code import {...
user2038538's user avatar
1 vote
1 answer
1k views

How to write a unit test for a mat dialog using jasmine and Angular 7?

I am writing a unit test for the method in a component that opens a mat-dialog. Tried writing the following unit test to make sure if the dialog opens. But I am getting an error. component.ts: It has ...
Mia's user avatar
  • 41
1 vote
1 answer
3k views

Angular Test : Access elements of child component from parent

My Parent Component: html: <div *ngIf="data.errorMsg.firstName !== 0"> <child (notes)="saveNote($event)" [errorType]="data.errorMsg.firstName" nameType="first name"></child> &...
SurajS's user avatar
  • 491
2 votes
3 answers
20k views

Why do I get a "error TS1005: ';' expected." error when running a simple Jasmine test?

I'm using Angular 7. I wrote a real simple test class, src/app/pastebin.ts, export class Pastebin { id: number; title: string; language: string; paste: string; constructor(...
Dave's user avatar
  • 17.4k
0 votes
0 answers
207 views

the Error Encountered undefined provider! is encountered even if the providers are defined

The Jasmine test cases are failing after adding active route imports. I have imported all the dependencies required. All the imports requires is added for active route the providers are included: ...
reema dass's user avatar

15 30 50 per page