Questions tagged [angular2-testing]
289 questions
4
votes
1 answer
angular 2 testing w/router
I have a component and when a user logs in it routes to a url called /dashboard I am really struggling figuring out why I am getting the following error.
cannot read property 'args' of undefined
I have been following the official docs on testing…

Bean0341
- 1,632
- 2
- 17
- 37
4
votes
0 answers
karma-test-shim.js calling TestBed.initTestEnvironment, but no effect. TestBed must be initialized again
I am currently trying to get unit testing working with Angular2 final and karma + jasmine.
I have the following problem:
TypeError: Cannot read property 'injector' of null if don't add: TestBed.initTestEnvironment(BrowserDynamicTestingModule,…

Toby
- 229
- 1
- 2
- 7
4
votes
1 answer
Angular 2.0.1 A platform with a different configuration has been created. Please destroy it first
I'm trying to run Angular 2 unit tests on an Angular 2 Component with Jasmine (I am not using Karma, however... just webpacking my code then running the tests in the default Jasmine SpecRunner.html).
When I run my code, I get the error: "A platform…

Targaryen
- 1,081
- 2
- 17
- 30
4
votes
1 answer
Angular2 - test that a injected private service method has been called
First, I understand that I should not be testing a private method, however I feel there are times that I should test if a private method was called based on some logic.
I'm building a wrapper service around the angular 2 http service so that I can…

HomeBrew
- 849
- 2
- 12
- 25
4
votes
2 answers
Test Angular 2.0.0 component with HTTP request
I have the following Angular 2.0.0 component:
import { Component, OnInit } from '@angular/core';
import { Http } from '@angular/http';
@Component({
selector: 'app-book-list',
templateUrl: './book-list.component.html',
styleUrls:…

Jason Swett
- 43,526
- 67
- 220
- 351
4
votes
1 answer
How to add providers in angular2 jasmine testing spec since addProvider is deprecated in RC6?
I am trying to write my beforeEach like this so that every it gets the required modules / providers:
beforeEach(() => addProviders([
BaseRequestOptions,
MockBackend,
{
provide: Http,
useFactory:…

user1532043
- 859
- 2
- 15
- 26
4
votes
2 answers
Unit test for a component with dependency which has dependencies, what's wrong?
I have annoying error that probably by my mistake I cannot resolve.
I have on simple component which is actually nothing else than a top-bar element in my web application.
This component as you can see has only one dependency, the UserService and it…

Vassilis Pits
- 3,788
- 4
- 33
- 48
4
votes
1 answer
how can i call methods by creating new instance of angular2 component in my spec file?
I have myComponent which contains method1, method2 and ngOnInit.
export class myComponent {
//input and output declaration
public myVar;
constructor( @Inject(ElementRef) private elementRef: ElementRef) {
}
public method1() { return…

heyayush
- 185
- 1
- 11
3
votes
1 answer
Angular 2+ Service Testing. Service imports are undefined at ng test runtime
I'm new to Angular and attempting to test an Angular 6 service which utilizes handlebars.js to build client-side html templates, based on input JSON / data.
The service produces the desired result in development, but I'm unable to build a test…

Andrew
- 1,406
- 1
- 15
- 23
3
votes
2 answers
Location class from @angular/common doesn't work in unit tests
For some reason Location.normalize() and other functions doesn't return correct response when I run tests:
import { Router } from '@angular/router';
import { Location } from "@angular/common";
import { TestBed, async, tick } from…

Yuri G.
- 33
- 4
3
votes
1 answer
Load all Components and Providers from one source for Angular Unit Tests
I have been learning Angular 2 unit testing for the last month or so and have come across a tedious process that I am trying to figure out how to get around. This tedious process has to do with importing every provider that a component uses for a…

Shamrocck
- 31
- 2
3
votes
1 answer
Angular 2 Testing Input Box Binding
I can't seem to test an input box bound to an Angluar2 model. I'm a little new to this so please bear with me.
I have a very basic Angular2 component which contains an inputbox bound to a model.
3
votes
1 answer
test cases got skipped in angular2
I have written some test cases ,when i try to run ng test only one test cases is being executed and the rest skipped
// my test.ts file
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import…

selenium 501
- 45
- 2
- 4
3
votes
1 answer
TestBed: Component doesn't compile when imported through a module
I am currently trying to write a set of unit test for a component that uses another component tag within its html.

Iltharion
- 165
- 2
- 12
3
votes
1 answer
Karma can't recognize angular directives
Our project structure follows this: Angular2-webpack-starter.
Our project successfully compiles, build and can be seen in the browser. No problems here.
But when we try to run the test cases using karma and jasmine we are getting this error.
FAILED…

RASHMI NALWAD
- 41
- 4