Questions tagged [angular2-testing]

289 questions
3
votes
1 answer

Can't bind to 'ngModel' since it isn't a known property of 'input'. test .spec.ts

I haev been linked to another ticket. This error ONLY occurs in test and I have imported the FormsModule per linked message. I am using Angular 2.2.1. ngModel not defined in 'ng test' I have imported FormsModule and ReactiveFormsModule to no…
KenF
  • 544
  • 4
  • 14
3
votes
1 answer

DebugElement.children has a different order than NativeElement.children

I have an html table and want to get all rows (s). However calling .children on a DebugElement or a NativeElement returns a different ordering. My table: 1 2 3 …
fwind
  • 1,274
  • 4
  • 15
  • 32
3
votes
1 answer

UnitTest Mock Http response in Angular2 (2.1.0) Service

I am very confused by the different sources online about testing Angular2, mainly due to differences in versions. I am using Angular 2.1.0 final and I don't understand how to mock a simple http response for my service test class below: import {…
nuvio
  • 2,555
  • 4
  • 32
  • 58
3
votes
1 answer

Angular 2 (Mock Ionic2) -- No provider for App

I'm trying to create a spec.ts for my application. Sadly this is using the LoadingController from ionic-angular. Now when I'm trying to configure the module, I will need to provide it with the LoadingController (since it's in the constructor of the…
Ivar Reukers
  • 7,560
  • 9
  • 56
  • 99
3
votes
1 answer

Angular2 2.0.0 Component Unit Test causes error: Bootstrap at least one component before injecting Router

Looking at previous similar questions, it doesn't seem that there was ever a clear answer for this. Here's what's happening. I'm building an angular2 app using the angular-cli tool (beta 16 running, with angular 2.0.1 and router 3.0.1. When I run…
sitesbyjoe
  • 1,861
  • 15
  • 21
3
votes
1 answer

Angular2 async testing issue with setTimeout

I am using Angular2.0.1 and was trying to write unit tests around an angular component with some async tasks. A fairly common thing to do, I'd say. Even their latest testing examples include these kind of async tests (see here). My own test would…
Ben
  • 1,537
  • 1
  • 17
  • 20
3
votes
1 answer

test cases failing when running ng test in angular2.0 with angular2-material components

I am using angular2.0 in my application I installed angular2-material components and imported in required modules I tried writing test case for one of my components //about.component.html

{{title}}

mounika20
  • 213
  • 2
  • 9
3
votes
1 answer

Angular 2 - angular-cli pipe test with dependencies

I'm trying to implement a test for a relatively isolated Pipe. I am using the latest version of angular-cli (with @angular 2.0.0). The pipe code is: import { Pipe, PipeTransform } from "@angular/core"; import { DatePipe, JsonPipe } from…
Sefi Ninio
  • 427
  • 1
  • 5
  • 12
3
votes
1 answer

How do you test Angular 2 directive that calls a service?

I used angular-cli to create a simple app to illustrate my problem. You can see all the code here: https://github.com/wholladay/tracking The directive calls a service whenever the containing element is clicked on. Therefore, I'd like to mock the…
3
votes
1 answer

Angular2/testing: how to run test with mock service provider?

Angular2 testing I want to run my component with the mock service, not the actual service. I have provided the mock service(MockMyService) in beforeEachProviders, still it is calling the actual service. describe('List view component', () => { …
Mike
  • 43
  • 1
  • 6
2
votes
2 answers

Why the angular unit test is not testing the content of the subscription in this service?

I'm using Angular 14. I'm trying to test this service: import { EnvironmentService } from './environment.service'; import { MsalService, MsalBroadcastService, MSAL_GUARD_CONFIG, MsalGuardConfiguration } from '@azure/msal-angular'; import {…
2
votes
1 answer

How would I mock route queryParams in ngOnInit() in a spec test

Failed: Cannot read property 'queryParams' of null at I'm assuming it's because I have the following in ngOnInit(): ngOnInit() { this.route.queryParams.subscribe(async params => { this.userInfo = await JSON.parse(params['user_info']); …
2
votes
1 answer

Angular 5 unit testing: How to make change detection work properly?

How to make change detection in unit tests work properly? From sources, changeDetection should be ran after microtasks are empty (including event tasks?). this._onMicrotaskEmptySubscription = ngZone.onMicrotaskEmpty.subscribe({ next: () => { …
2
votes
1 answer

Combine toHaveBeenCalledTimes with toBeGreaterThan

Is there a way in jasmine where I can combine toHaveBeenCalledTimes with toBeGreaterThan? I want to know whether the spy object has called a particular method at least 2 times. spy Object spyOn(component.videos, 'update').and.callThrough(); I know…
Amit Chigadani
  • 28,482
  • 13
  • 80
  • 98
2
votes
1 answer

How to write a unit test for observable finally block in jasmine - angular 2

I have a save method. public saveJob(formData: any, redirect: boolean = false): Observable { if (!this.checkJobValidity()) { return Observable.of(null); } return this.service.edit(this.job) .do((data) => { …
Josf
  • 776
  • 1
  • 8
  • 21