Questions tagged [angular2-testing]

289 questions
29
votes
1 answer

Mocking service in a component - mock ignored

This time I'm trying to mock a service (that does http calls) to test a component. @Component({ selector: 'ub-funding-plan', templateUrl: './funding-plan.component.html', styleUrls: ['./funding-plan.component.css'], providers:…
youri
  • 3,685
  • 5
  • 23
  • 43
27
votes
2 answers

How to unit test if an angular 2 component contains another component

I'm quite new to angular 2. I have a component which in turn has some other components in its template. How do I write unit tests to check if my parent component consists of other components. Mentioning a sample or directing me to a resource would…
Chan15
  • 929
  • 2
  • 9
  • 16
27
votes
1 answer

Angular2 how to unit test a custom validator directive?

I wrote a very simple custom validator for an input field: import { Directive } from '@angular/core'; import { AbstractControl, NG_VALIDATORS } from '@angular/forms'; function numberValidator(c: AbstractControl) { if (!c.value) return null; …
26
votes
3 answers

The pipe 'translate' could not be found , angular2 component testing

I am working on component testing with angular2. in my html template i use the translate pipe. This is the code of the test : import { ComponentFixture, TestBed ,getTestBed} from '@angular/core/testing'; import { By } from…
user3518668
  • 359
  • 1
  • 4
  • 14
26
votes
6 answers

Testing - Can't resolve all parameters for (ClassName)

Context I created an ApiService class to be able to handle our custom API queries, while using our own serializer + other features. ApiService's constructor signature is: constructor(metaManager: MetaManager, connector: ApiConnectorService,…
25
votes
1 answer

How to unit test a FormControl in Angular2

My method under test is the following: /** * Update properties when the applicant changes the payment term value. * @return {Mixed} - Either an Array where the first index is a boolean indicating * that selectedPaymentTerm was set, and…
chap
  • 1,860
  • 5
  • 24
  • 39
24
votes
1 answer

How to mock a observable stream while testing angular2 components?

I am writing test cases for angular2 components. I had created a service which uses observable stream as below: import {Injectable} from '@angular/core' import {Subject} from 'rxjs/Subject'; import {User} from…
Bhushan Gadekar
  • 13,485
  • 21
  • 82
  • 131
23
votes
4 answers

How to change value of a select box in angular2 unit test?

I have an Angular2 component that contains a select box that looks like