Questions tagged [angular2-testing]

289 questions
9
votes
2 answers

Cannot read property unsubscribe of undefined: Angular2 testing

I am trying to test a component which has ngOnDestroy() method which has all the unsubscribe() method calls. But, while testing, when I run my testing file (spec file) it gives me error saying: cannot read property 'unsubscribe' of undefined I have…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
8
votes
3 answers

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. But I need to change Angular application URL in…
Sameer K
  • 799
  • 1
  • 7
  • 26
8
votes
2 answers

Angular 2(4) component with ControlValueAccessor testing

I would like to test component which implements ControlValueAccessor interface for allow to use [(ngModel)] in my custom component, but the issue is that usual inputs comes correct but ngModel - undefined. Here is code example: @Component({ …
qwe asd
  • 1,598
  • 3
  • 21
  • 31
8
votes
1 answer

Testing a component, which depends on a route param

I have a question about testing a routed component in angular2. Here is a simple component, which depends on a route with a parameter 'foo'. The attribute foo in the component will be set to the value of the parameter. import {Component, OnInit}…
be-ndee
  • 1,153
  • 3
  • 13
  • 19
8
votes
1 answer

Angular2 unit testing - why nativeElement has empty CSSStyleDeclaration

I'm trying to test a simple header component that has a button and when being focused - opens a dropdown using just css visibility property. This is the html:
8
votes
3 answers

How do I Mock an Angular 2 route?

I have the following code... export class LoginComponent { userName: string; password: string; rememberMe: boolean = false; constructor( private auth: AuthenticationService, private router: Router) { ... } …
Jackie
  • 21,969
  • 32
  • 147
  • 289
8
votes
1 answer

Cannot read property 'injector' of null jasmine angular 2

I'm getting this error when running a jasmine spec in angular 2: Cannot read property 'injector' of null jasmine angular 2 stack trace: TypeError: Cannot read property 'injector' of null at TestBed._createCompilerAndModule…
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
8
votes
2 answers

Angular 2.1 Cannot set base providers because it has already been called(…)

I'm trying to test a basic angular 2 component that Includes a service. When I run my test I'm getting the following errors. The component, service and test are pretty small, they run fine in the browser as well. I'm not sure what I am missing from…
Jimi
  • 1,867
  • 7
  • 31
  • 55
7
votes
2 answers

@angular/core/testing has no exported member 'MockApplicationRef'

I want to run my old angular2 unit-test with new RC4 version, but I have a problem. What happened to MockApplicationRef ? What I should use here instead ? provide(ApplicationRef, { useClass: MockApplicationRef})
Dariusz Filipiak
  • 2,858
  • 5
  • 28
  • 39
6
votes
2 answers

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: UserLoginService, public router:…
AleGallagher
  • 1,745
  • 7
  • 30
  • 40
6
votes
2 answers

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 able to get it work. Here is my…
Amit Chigadani
  • 28,482
  • 13
  • 80
  • 98
6
votes
0 answers

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 the Angular website it looks like the MockBackend…
6
votes
1 answer

why ngForm "controls" property is empty in my test? (Angular)

I have a component which employs template-driven form
dKab
  • 2,658
  • 5
  • 20
  • 35
6
votes
1 answer

Angular2 testing: change the injected value of a service

I am testing a simple service. The service uses 2 values from another service. Basically, I would like to test those 2 values : isLogged = false and isLogged = true. Is it possible to just change the value of an injected service, or do I need to do…
user4676340
6
votes
2 answers

How to Unit Test Angular 2 routing params

Say that I want to simply unit test a component that takes parameters taken from a part of the route. For instance, my component's ngOnInit looks like this: ngOnInit() { this.route.parent.params.switchMap((params: Params) =>…
Arwin
  • 973
  • 1
  • 10
  • 21