Questions tagged [angular2-testing]

289 questions
2
votes
0 answers

Angular 2 Testing the Router Module

I am attempting to test my Router in Angular 2.2.1 to ensure the proper routes are set up and going to the expected location. I've done Google research and have read and re-read the app.component.router.spec.ts file from the example at…
user27519
  • 21
  • 3
2
votes
1 answer

Angular 2 fixture does not contain styles of component in unit test

I'm having trouble with the following. This is a unit test for a directive, the directive itself should simply change the height style property for the element it's on. I am using a test component as a context for this test. The trouble is the…
m.fox
  • 21
  • 6
2
votes
0 answers

angular 2 unit testing with karma and jasmine, how to simulate offline and timeout

Is there a way to utilise testing angular2 app's behaviour in offline, specifically http requests? Some way to mock offline response maybe. How could one test http request timeouts? I already asked question regarding this issue here, but could not…
Petr Marek
  • 1,381
  • 1
  • 15
  • 31
2
votes
0 answers

How I can write automation script to test draw canvas in Angular 2 by Protractor

I have a simple project to draw line in canvas html5 by Angular 2. How I can write script automation to test draw canvas in Angular 2 by Protractor. This code use angular 2 and I want to test automation it use Protractor. Full source code. ///…
Tam Vo
  • 301
  • 4
  • 13
2
votes
1 answer

Jasmine route spy - undefined is not an object (evaluating 'navigate.calls.mostRecent().args')

I am trying to unit test an angular2 component which uses routeing. I have: class MockRouter { } class MockAuth { isLoggedIn(){ return false; } } describe('Home', () => { beforeEach(() => TestBed.configureTestingModule({ providers:…
George Edwards
  • 8,979
  • 20
  • 78
  • 161
2
votes
0 answers

Error in Component class Component - inline template:7:24 caused by: Cannot read property 'subscribe' of undefined

I use angular 2.1.0 modules in my current application. I get the error below if i run unit test on a component that has a routerLink attribute. Failed: Uncaught (in promise): Error: Error in ./MyComponent class MyComponent - inline template:7:24…
2
votes
0 answers

Spy on a class variable

I have a
element that has a (click) event attached to it which toggles some class variable, like the following:
For testing the click event first I have to grab the div event by…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
2
votes
1 answer

If 'some-component-tag' is an Angular component and it has 'some-input-var' input, then verify that it is part of this module

I'm trying to test my Angular 2 application, following the Angular2 testing doc. The component I'm currently testing has an external template (I have tested other components with external templates, and there tests run fine), but whenever I try to…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
2
votes
1 answer

Angular 2 Testing Component Gives "Error: Uncaught (in promise): Error: Template parse errors"

I've recently made an ng2 (using 2.0.1) app with multiple components and services. I'm in the middle of testing (Karma Jasmine) my HeaderComponent which contains my UserService (Which uses an extended Http class). I've replicated simple tests from…
Atheteo
  • 43
  • 1
  • 9
2
votes
1 answer

Properly inject dependency in Angular2 tests

I'm struggling with testing an Angular2 component that has a service injected. The test code is below but basically: • SearchComponent takes a FightService in the constrctor. • The constructor calls a flightsService.getFlights() which fires off an…
big_tommy_7bb
  • 1,257
  • 2
  • 21
  • 37
2
votes
1 answer

TypeError: Cannot read property 'injector' of null after upgrading to Angular 2.0 final

After upgrading from Angular 2 RC5 to 2.0 Final, I'm seeing the following errors when running my tests. I'm not sure what the problem is. TypeError: Cannot read property 'injector' of null at TestBed._createCompilerAndModule…
Matt Raible
  • 8,187
  • 9
  • 61
  • 120
2
votes
1 answer

RouteLink testing angular2

I am testing a Component that use the RouteLink directive like this way : let comp: AppComponent; let fixture: ComponentFixture; let el: DebugElement; let injector: Injector; let languageService: TranslateService; let location:…
2
votes
1 answer

Angular 2.0.0 Testing a component with router

Given the following component: import {Component, OnInit} from '@angular/core'; import {Route, Router} from '@angular/router'; @Component({ selector: 'app-index', templateUrl: './index.component.html', styleUrls:…
James Kleeh
  • 12,094
  • 5
  • 34
  • 61
2
votes
1 answer

Angular2 testing service -- undefined service

Hi I am trying to write unit tests for my service following this procedure: https://developers.livechatinc.com/blog/testing-angular-2-apps-dependency-injection-and-components/ but I keep getting an error. Here is the service test import…
es3735746
  • 841
  • 3
  • 16
  • 40
2
votes
1 answer

using MockBackend to test function that then calls .map

I am trying to write unit tests for my service which makes Http requests. I have a service that returns a Http.get() request followed by a .map(). I am having trouble getting my mocked backend to return something that doesn't error on the .map().…
dafyddPrys
  • 898
  • 12
  • 23