Questions tagged [angular2-testing]

289 questions
0
votes
0 answers

Protractor E2E testing on Angular2: Page not loaded ERR_CONNECTION_REFUSED

I have been stuck for 2 days trying to create E2E tests for our angular2 application. We used angular-cli to scaffold our whole app: our app is served correctly with ng serve or ng build. Therefore, we are able to deploy it successfully on a remote…
Hopkins
  • 21
  • 2
0
votes
1 answer

Angular2 test component

Hi i'm trying to get into testing my components in Angular2 but have ran into an issue when i'm trying to mock my service. I'm currently following the Angular2 docs on testing. I'm calling my backend API that i've built from the angular service,…
mertje
  • 486
  • 1
  • 7
  • 15
0
votes
0 answers

Angular2 Tests Routerstub isnt used

I want to test the right routing to another Component. I swap the original Router with my RouterStub, so my Spy can spy on 'navigateByUrl'. As I understand it, navigateByUrl should be overwritten, and the FakeMethod will be executed. The Test…
0
votes
2 answers

regex time format validation: angular 2

I'm trying to add regex validation (or any better validation approach, if it exists) to validate time in the following format: 00:00:00:00 (hous:minutes:seconds:miliseconds) none of the tutorials I saw online shows how to do this using angular 2.…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
0
votes
1 answer

Angular 2 test setup

I'm trying to test an Angular 2 component with the following setup: import { TestBed } from '@angular/core/testing'; import { By } from '@angular/platform-browser'; import { GroceriesListComponent } from './groceries-list.component'; import {…
MattDionis
  • 3,534
  • 10
  • 51
  • 105
0
votes
1 answer

Angular2 mocking injectable service

I use Angular 2 Karma-Jasmine. I have AService, it("test", () => { let x:any = function1('value', aService); expect(x).toEqual("value1"); }); Now AService has getA() method, and function1 used getA() method. I want mock AService.getA…
emanuel07
  • 738
  • 12
  • 27
0
votes
2 answers

sample code: making mocks in angular2

I am learning Angular2. In DI pages, there is sample code for mocking. https://angular.io/docs/ts/latest/guide/dependency-injection.html What does it mean let mockService = {getHeroes: () => expectedHeroes } It looks like define…
Yusei
  • 27
  • 1
  • 6
0
votes
1 answer

Creating an instance of a component: Angular2 unit testing

I'm trying to create an instance of a component in component's testing file. But when I do something like this: let componentInstance = new component(); it hits the component constructor, which further has something in its body, constructor( param…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
0
votes
1 answer

Dependency unit testing: Angular 2

I'm trying to create unit tests for my app. What my primary goal is to create a basic spec file for a component or service which just checks if all the services or components on which our component depend are getting imported (that's the most basic…
Aiguo
  • 3,416
  • 7
  • 27
  • 52
0
votes
1 answer

No provider for AngularFire

I'm using AngularFire2. I got this exception when running tests. This is what my test looks like: import {inject, TestBed} from '@angular/core/testing'; import {FIREBASE_PROVIDERS, defaultFirebase, AngularFire} from 'angularfire2'; describe('stock…
user73554
  • 93
  • 1
  • 9
0
votes
1 answer

Testing Angular2 Directive without creating a new Component

I want to test a directive with the current Angular2 version (RC6). I'm reading from NG2 Test recipes that the way to go is creating an ad-hoc Component that implements your directive in the template. @Component({ selector: 'container', …
Bolza
  • 1,904
  • 2
  • 17
  • 42
0
votes
1 answer

Testing Angular2 component @Input and @Output

How can I structure tests for Angular2 simple form component: import { Component, EventEmitter, Input, Output } from '@angular/core'; @Component({ selector: 'user-form', template: `
tomaszbak
  • 8,247
  • 4
  • 44
  • 37
0
votes
1 answer

Typescript + Angular2 test fails because of a JS library dependency

I use jsfeat javascript library in my Angular2 project. I put this at the beginning of my .ts and .spec.ts files: declare var jsfeat: any; I included jsfeat.js in my index.html. Now I want to run Angular2 tests, but I get: ReferenceError: jsfeat is…
Admdebian
  • 630
  • 6
  • 17
0
votes
1 answer

DI with beforeEach in Angular 2

I want to do the following: describe('Questions', () => { var rest: RestService; var mockBackend: MockBackend; beforeEach((done) => { console.log('Executing before each'); inject([RestService, XHRBackend], (_rest:…
Dr.Knowitall
  • 10,080
  • 23
  • 82
  • 133
0
votes
1 answer

Angular2 Unit Test Component getting "No Provider for DirectiveResolver"

I'm getting the following error: Error: No provider for DirectiveResolver! Error: DI Exception at NoProviderError.BaseException [as constructor] (http://localhost:9876/jspm_packages/npm/angular2@2.0.0-beta.17/src/facade/exceptions.js:19:23) …
Bolza
  • 1,904
  • 2
  • 17
  • 42
1 2 3
19
20