karma-jasmine

MockService still causes error: Cannot read property 'subscribe' of undefined

风流意气都作罢 提交于 2021-01-27 07:27:17
问题 I'm new to Angular testing. So, I was following this pluralsight course. I keep getting the same error Cannot read property 'subscribe' of undefined no matter what I do. describe('AnnualReportComponent', () => { let fixture: ComponentFixture<AnnualReportComponent>; let mockReportService; let REPORTITEMS = [ { id: 1, title: 'title 1' }, { id: 2, title: 'title 2' }, { id: 3, title: 'title 3' } ] beforeEach(() => { mockReportService = jasmine.createSpyObj('ReportService', ['getAnnualReport']);

App testing return “NullInjectorError: No provider for Location!”

我只是一个虾纸丫 提交于 2021-01-22 05:18:09
问题 Testing an app in Angular 7 with Karma, I can't remove the error in subj. I have searched various places (mostly here) but either the solutions don't work or are not relevant to my case. App.component.html: <app-header></app-header> <router-outlet></router-outlet> Header.component.ts: import { Component, OnInit, ViewChild, ElementRef, AfterViewInit, EventEmitter, Output } from '@angular/core'; import { Router } from '@angular/router'; import { Location } from '@angular/common'; @Component({

App testing return “NullInjectorError: No provider for Location!”

≡放荡痞女 提交于 2021-01-22 05:16:24
问题 Testing an app in Angular 7 with Karma, I can't remove the error in subj. I have searched various places (mostly here) but either the solutions don't work or are not relevant to my case. App.component.html: <app-header></app-header> <router-outlet></router-outlet> Header.component.ts: import { Component, OnInit, ViewChild, ElementRef, AfterViewInit, EventEmitter, Output } from '@angular/core'; import { Router } from '@angular/router'; import { Location } from '@angular/common'; @Component({

Is it possible to install NVM when I already have installed nodejs 8 on Ubuntu?

爷,独闯天下 提交于 2021-01-22 05:15:12
问题 I have installed nodejs 8, I can't run karma tests with angular 1.. As specified on Karma official website Note: Karma currently works on Node.js 0.10, 0.12.x, 4.x, 5.x, 6.x, and 7.x. See FAQ for more info. , I guess problem might be in my node version, they recommend to install node via NVM but I already have installed node 8.. is it possible to install nvm and include there my current nodejs? 回答1: Q: Can I still install nvm when I already got an existing node installation? A: Yes. nvm

Is it possible to install NVM when I already have installed nodejs 8 on Ubuntu?

偶尔善良 提交于 2021-01-22 05:12:25
问题 I have installed nodejs 8, I can't run karma tests with angular 1.. As specified on Karma official website Note: Karma currently works on Node.js 0.10, 0.12.x, 4.x, 5.x, 6.x, and 7.x. See FAQ for more info. , I guess problem might be in my node version, they recommend to install node via NVM but I already have installed node 8.. is it possible to install nvm and include there my current nodejs? 回答1: Q: Can I still install nvm when I already got an existing node installation? A: Yes. nvm

Angular 8 test with Karma / Jasmine -> 100% code coverage not covered for loadChildren in angular routes

人走茶凉 提交于 2021-01-03 03:02:25
问题 After upgrading from angular 7 to 8, there were breaking changes in loadChildren for your application routes. When these are fixed and all test are running, i don't get a 100% code coverage (anymore), because the loadChildren isn't a 'string' anymore, but a LoadChildrenCallBack. How do i test this particulary part of code setup: import { NgModule } from '@angular/core'; import { RouterModule, RouterStateSnapshot, Routes } from '@angular/router'; import { RouterStateSerializer,

Angular 8 test with Karma / Jasmine -> 100% code coverage not covered for loadChildren in angular routes

混江龙づ霸主 提交于 2021-01-03 02:59:23
问题 After upgrading from angular 7 to 8, there were breaking changes in loadChildren for your application routes. When these are fixed and all test are running, i don't get a 100% code coverage (anymore), because the loadChildren isn't a 'string' anymore, but a LoadChildrenCallBack. How do i test this particulary part of code setup: import { NgModule } from '@angular/core'; import { RouterModule, RouterStateSnapshot, Routes } from '@angular/router'; import { RouterStateSerializer,

When to use waitForAsync in angular

喜你入骨 提交于 2020-12-13 03:34:13
问题 From documentation we can read: waitForAsync(fn: Function): (done: any) => any Wraps a test function in an asynchronous test zone. The test will automatically complete when all asynchronous calls within this zone are done. Can be used to wrap an inject call. I could not understand, when to use waitForAsync function? What's the difference between waitForAsync vs ( async or fakeAsync )? 回答1: In Angular 10.1.0, waitForAsync() has replaced async() to avoid confusion, but is otherwise exactly the

When to use waitForAsync in angular

痴心易碎 提交于 2020-12-13 03:31:59
问题 From documentation we can read: waitForAsync(fn: Function): (done: any) => any Wraps a test function in an asynchronous test zone. The test will automatically complete when all asynchronous calls within this zone are done. Can be used to wrap an inject call. I could not understand, when to use waitForAsync function? What's the difference between waitForAsync vs ( async or fakeAsync )? 回答1: In Angular 10.1.0, waitForAsync() has replaced async() to avoid confusion, but is otherwise exactly the

Angular 2 and Jasmine unit testing: cannot get the innerHtml

陌路散爱 提交于 2020-12-08 06:20:23
问题 I am using one of the examples that test a component 'WelcomeComponent': import { Component, OnInit } from '@angular/core'; import { UserService } from './model/user.service'; @Component({ selector: 'app-welcome', template: '<h3>{{welcome}}</h3>' }) export class WelcomeComponent implements OnInit { welcome = '-- not initialized yet --'; constructor(private userService: UserService) { } ngOnInit(): void { this.welcome = this.userService.isLoggedIn ? 'Welcome ' + this.userService.user.name :