Questions tagged [angular2-testing]

289 questions
2
votes
0 answers

jasmine unit test error when adding Cookie Service

while writing jasmine unit test case for one of my angular 2 component, if I add CookieService in provider list then all remaining other component unit test cases are failing. If I remove CookieService from provider list then test cases are working…
2
votes
1 answer

How to test a Floating Action Button in Ionic2

I have an Ionic2 project, with the Unit Testing setup based on the clicker repository. I try to use a Floating Action Button in a component but it throws an exception when running the unit tests. I added a FAB to the plain clickr app to demonstrate…
Robert
  • 23
  • 1
  • 5
2
votes
1 answer

Not able to click the button using element(by.css()) with protractor on ionic2

I am able to navigate to the page, but on the navigated page I am trying to click the button which is showing error as follows: × navigates to the next page on click - Failed: unknown error: Element
2
votes
1 answer

How to mock a service that contains http request and returns an observable?

Below is my Service class which is taking a url which has a json format data. service.ts import { Injectable } from "@angular/core"; import { Http } from '@angular/http'; import { Observable } from "rxjs/Observable"; …
user8348978
  • 81
  • 1
  • 1
  • 7
2
votes
1 answer

Routing testing - Location.path() always return empty ""

I'm following this tutorial. This is the only modern example I found to test the routing. In time I'd like to use mock components. Sadly, the delivered plunker does not work. Router: App navigate to "" redirects you to /home Expected '' to be…
Cerdicipe
  • 188
  • 3
  • 13
2
votes
1 answer

How to append a DOM element to an angular 2 TestBed?

To cut to the chase, I would like to know if there is a way to prepend a DOM element to the test DOM. I'm new to testing but something like fixture.degugElement.prepend('div'). From what I've learned about testing this probably reveals a design…
Nate May
  • 3,814
  • 7
  • 33
  • 86
2
votes
2 answers

e2e testing with protractor in angular 2

on back-end i use Spring Boot, on front-end i use Angular 2. i write simple tests for my front-end, but i want to mock my back-end. i search in google but i do not found answer for my question. how to mock back-end on testing with protractor? sorry…
2
votes
0 answers

Karma not recognizing Angular2 modules and components with Rails Webpacker

My team updated the Rails version of our application to 5.1 so we could use Webpacker, a wrapper to use Webpack with Rails and then use Angular 2 properly. We started setting up the test suite for the Angular 2 modules using Karma + Jasmine +…
2
votes
1 answer

Angular2 Jasmine spyOn http calls

I would like to spy on the Http service to see if it calls the right endpoint. Is it possible to do that ? So far, in my services, all I'm testing is that they send back data ... I would like to make them more useful. If you ever need it, here is…
user4676340
2
votes
1 answer

Testing route navigation without an outlet in Angular

I am writing a spec for an Angular component that displays a button that will navigate to another page. The component makes use of Router::navigate() but does not itself have a router outlet. A parent component has the outlet. In my spec, the test…
ebakunin
  • 3,621
  • 7
  • 30
  • 49
2
votes
1 answer

Angular 2/Jasmine, updating an activated route params subscription within each describe/it block

Given a simple component that subscribes to the activated route query params in ngOnInit: export class FooComponent implements OnInit { private queryParams: any; constructor( private activatedRoute: ActivatedRoute ) { } ngOnInit() { …
user3244479
2
votes
1 answer

Is there a FactoryGirl version of Jasmine Karma testing?

In Ruby, you can use FactoryGirl to set factories where you save test objects. Is there such a practice in Jasmine/Karma testing? Currently having to create a lot of instances of the same objects. I was wondering if there are any ways to do this.
Ka Mok
  • 1,937
  • 3
  • 22
  • 47
2
votes
1 answer

Angular2 - Mocking up Angular2-toaster for Jasmine Unit testing

More Generalize the question - How to mock up and external library used in Angular2 In my application i am using Angular2-toaster for popup messages. In order write unit test suite(Jasmine)to one of the component, I tried to mock up the toaster…
2
votes
1 answer

Expected [ '/' ] to be [ '/' ] - they look the same

I'm trying to test a router outlet. I originally had: expect(landingPageLink).toBe('/', '1st link should go to landing page'); I was getting this error: Error: Expected [ '/' ] to be '/', '1st link should go to landing'. So changed it to…
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287
2
votes
1 answer

Add component stylesheet to Jasmine test in Angular 2

I'm running my unit tests and seeing the actual application page below the results. It'd be nice if it had the styling applied to it, as the images etc go massive and it's not worth looking at. Here is my setup code: …
BeniaminoBaggins
  • 11,202
  • 41
  • 152
  • 287