Questions tagged [angular2-testing]
289 questions
2
votes
0 answers
Angular 2 RC6 testing: TypeError: Cannot read property 'injector' of null
After a couple of hours of searching for the solution, I'm still getting the following error while testing my angular2 application:
TypeError: Cannot read property 'injector' of null
at TestBed._createCompilerAndModule…

Zolcsak Tamas
- 147
- 1
- 8
2
votes
1 answer
Angular2 - Testing a Component with templateUrl resulting in "Unhandled Promise rejection"
I'm currently writing a simple test to test an Angular 2 component whose template is referenced with a templateUrl. I am currently using webpack to perform the tasks required, including testing. I was following the webpack guide on the angular site …

JeanPaul A.
- 3,613
- 1
- 20
- 29
2
votes
1 answer
Angular 2 RC5 Testing Promises in ngOnInit Not Working
I am trying to test a structural directive named MyDirective with Jasmine. The Angular version used is RC5.
// Part of the MyDirective class
@Directive({selector: '[myDirective]'})
export class MyDirective {
constructor(protected templateRef:…

jayscript
- 319
- 2
- 5
- 13
2
votes
1 answer
How to test this servie in angular2 RC5?
I am learning angular2 RC5 now. I want to test following service in angular2 RC5 but I am not able to configure it somehow.
import { Injectable } from '@angular/core';
import { Http, Response,Headers } from '@angular/http';
import…

Bhushan Gadekar
- 13,485
- 21
- 82
- 131
2
votes
0 answers
Browserify Bundle Error when Running in Karma
When I run Karma with this configuration:
module.exports = function(config) {
'use strict';
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '../../',
// frameworks to use
//…

Haddar Macdasi
- 3,477
- 8
- 37
- 59
2
votes
0 answers
Injecting another service into service for testing - Angular2
I have two services, and one of them is dependent on another:
UserService:
@Injectable()
export class UserService {
constructor(private apiService: ApiService){}
...
}
ApiService:
@Injectable()
export class ApiService {
constructor(){}
…

user2255226
- 204
- 3
- 10
2
votes
1 answer
routerLinkActive directive causes undefined is not an object (evaluating 'router.events.subscribe')
I am using Angular2 RC3 and the new router. My HTML ...
routerLinkActive applies…

danday74
- 52,471
- 49
- 232
- 283
2
votes
2 answers
Using Angular 2's TestComponentBuilder confuses me
I'm working on an Angular 2-rc3 application and I have some unittests set up and they're working, yay! I just don't understand why they have to be written the way they do. And even more amazing, all the examples I see have the same approach.…

J.P.
- 5,567
- 3
- 25
- 39
2
votes
1 answer
Angular2 + jquery autocomplete Component: unable to call methods on component inside spec file
I have jquery autocomplete method being used inside angular2 which calls service to fetch data from api.
Here is myComponent.ts :
export class myComponent {
private myVar;
private binding1;
private binding2;
constructor( @Inject(ElementRef) private…

candidJ
- 4,289
- 1
- 22
- 32
2
votes
2 answers
Angular 2.0.0-rc.1: How to test elements on the view or content (e.g. @ViewChildren, @ContentChildren)
I have a component that gets data from a service which creates children on the View. Those children are only available when the View is created. In my example below the View is not created before it reaches its tests, thus test 2…

Steve Van Opstal
- 1,062
- 1
- 9
- 27
2
votes
1 answer
Angular2 testing logic before .subscribe
I am currently writing unit tests for one of my components. In particular, I have login(): void function. Here's the simplified logic:
login(): void {
this.showSpinner = true;
this.userService.login(loginData)
.subscribe(result => {
…

user2255226
- 204
- 3
- 10
1
vote
0 answers
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 issue). I have many custom services so using…

Mihir
- 531
- 2
- 10
- 35
1
vote
2 answers
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: Error: This test module uses the component…

Mike K.
- 543
- 3
- 14
- 46
1
vote
1 answer
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 { Component } from '@angular/core';
import { Meta }…

Alex Slav
- 175
- 1
- 10
1
vote
1 answer
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 (registerOnChange, ...)
@Component({
selector:…

Nealv
- 6,856
- 8
- 58
- 89