Questions tagged [angular-unit-test]

Questions about Angular unit testing. Use this tag for Angular unit testing questions which are not specific to an individual version. Do not use this tag for the older AngularJS (1.x) web framework uni testing questions.

Angular unit testing is based on two systems. Jasmine (The testing framework) and Karma (The test runner).

The Angular CLI takes care of Jasmine and karma configuration for you.

You can fine-tune many options by editing the karma.conf.js and the test.ts files in the src/ folder.

The projects that you create with the CLI are immediately ready to test. Just run ng test CLI command to run the tests.

Useful Links

256 questions
0
votes
1 answer

Not loading test cases generated in karma-jasmine framework

I am trying to write a simple test case for a controller, but it doesn't give any error as well doesn't load the test case I have written. app.js var myApp = angular.module('myApp',[ 'ui.bootstrap', 'dialogs', 'ui.router','base64','ngtimeago', …
0
votes
1 answer

how to unit test assignments in templates

I have part of template
koral
  • 2,807
  • 3
  • 37
  • 65
0
votes
2 answers

When do you have to wrap callback function of a spec with Async?

For some reason these two specs are passing, however the second spec is testing interpolation within the template, with async data from a service. Why is it not necessary to wrap the callback function with async? describe('SaangComponent', () => { …
0
votes
1 answer

How to implement a unit test for Angular JS controller with ajax service?

I have tried to write unit test for below code, but I can't able to achieve it. Service code: angular.module('ActivityApp').service('PersonService', [ '$http', function ($http) { var person = function () { return…
LTA
  • 191
  • 3
  • 16
0
votes
1 answer

Angular 4/5 unit test case .toBe in Services

I am trying to write test case for calling Service and getting response from HTTP. Reference Now the problem is as following : expect(data.length).toBe(12); Even though data.length is 100, This code does not throw any exception it('Should call…
Sangwin Gawande
  • 7,658
  • 8
  • 48
  • 66
0
votes
1 answer

How to inject http to class constructor in unit testing angular class using jasmine?

I have a abstract class called logPublisher. Below is the code: export abstract class LogPublisher { location: string; abstract log(record: LogEntry): Observable; abstract clear(): Observable; } Class LogWebApi…
user2439903
  • 1,277
  • 2
  • 34
  • 68
0
votes
1 answer

why are the tests failing

Trying to test http get service here but the test fails. why is it not working. I have provided all the dependencies and everything but still it's giving the response as undefined and when I run the karma test runner the test fails to give the…
SONGSTER
  • 585
  • 3
  • 11
  • 28
0
votes
1 answer

angular mouse enter unit test is not working

I am trying to test a mouse enter in angular 4 karma unit testing, There are not errors but the mouse enter is not calling the method binded to the mouse enter event.
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
-1
votes
1 answer

Angular spectator testing: target component-level service

In my Angular app I have a service which is provided at a component level: @Component({ selector: 'my-component', templateUrl: './my.component.html', providers: [MyService], }) export class MyComponent implements OnInit, OnDestroy { ... } I'm…
-1
votes
1 answer

How to test custom event emitter service in Angular 12

I have implement component communication using emit emitter service. service.ts import { EventEmitter, Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class BroadcastService { updateDetails = new EventEmitter(); …
-1
votes
2 answers

Resolved - ActivatedRoute angular unit test

I am facing an issue when testing this code: constructor( private valuePairService: ValuePairService, private sanitizer: DomSanitizer, private service: Service, private router: Router, private route: ActivatedRoute )…
beanic
  • 539
  • 6
  • 22
-1
votes
1 answer

How to Unit Test MatBottomSheet

I am getting an error that DependentComponent's properties are not set. I want to ignore calling DependentComponent - this._bottomSheet.open(DependentComponent), but not sure how to achieve that. I guess mockBottomSheetRef.open.and.callThrough(); is…
Adrita Sharma
  • 21,581
  • 10
  • 69
  • 79
-1
votes
1 answer

Angular Unit Test : Expected 3 arguments, but got 1

I'm currently doing unit testing of an Angular app. I'm new to Angular Unit Testing. I have downloaded the angular app from https://github.com/gothinkster/angular-realworld-example-app for the interest of time. As I'm new to Unit Test I saw some…
-1
votes
2 answers

Angular - Karma unit test not working, why?

As the title suggests, I'd like to ask if anyone knows the solution to how to get this unit test to pass, after adding the support service to the test123 component, it won't display true anymore no matter what I do. Image sample of the code and…
-1
votes
1 answer

Testing difficulty in Login Module

I have been testing my login module but the subscribe is not getting tested and i cannot check for localstorage also. I am a beginner so far I have done this import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import…
Anand Trivedi
  • 123
  • 6
  • 15
1 2 3
17
18