angular – Angular9 & # 39; SyntaxError: Unexpected end of JSON entry & # 39; in test with Karma Jasmine using observables with Firebase

I am a beginner using Angular9 and Firebase. I am a tutorial that teaches Angular9, firebase and TDD to pursue Karma Jasmine. In fact, I have a test that failed because the Json return object from a firebase http call returns an empty json. I have tried to call this URL by browser and it works, the browser returns Json correctly.

This is the Karma Jasmine error:

CartService > should have callHttp woeking
SyntaxError: Unexpected end of JSON input
    at UserContext. (http://localhost:9876/_karma_webpack_/src/app/services/cart/cart.service.spec.ts:111:32)
    at UserContext. (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:1749:1)
    at TestBedRender3.execute (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:3137:1)
    at UserContext. (http://localhost:9876/_karma_webpack_/node_modules/@angular/core/__ivy_ngcc__/fesm2015/testing.js:4299:22)
    at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:364:1)
    at ProxyZoneSpec.onInvoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:292:1)
    at ZoneDelegate.invoke (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:363:1)
    at (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-evergreen.js:123:1)
    at runInTestZone (http://localhost:9876/_karma_webpack_/node_modules/zone.js/dist/zone-testing.js:545:1)

The affected class is:

import { TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
import { CartService } from './cart.service';
import { AngularFireModule } from '@angular/fire';
import { AngularFirestore, AngularFirestoreModule } from '@angular/fire/firestore';
import { CartList } from './';
import { Observable } from 'rxjs';
import { MockBackend } from '@angular/http/testing';
import { Http, ConnectionBackend, BaseRequestOptions, Response } from '@angular/http';
import { httpFactory } from '@angular/http/src/http_module';
import { JsonPipe } from '@angular/common';

export const environment = {
  production: false,
  firebase: {
    apiKey: "AIzaSyDNW48hAmvH8eAZpbeflRKb0khY5Blzsqg",
    authDomain: "",
    databaseURL: "",
    projectId: "angularfirebasegb",
    storageBucket: "",
    messagingSenderId: "388340512107",
    appId: "1:388340512107:web:2cf5e9a1daea5cfaf1082e",
    measurementId: "G-L43R4QN2LN"

let AngularFireStoreMock = {
  collection: function (param: any) {
    return {
      // mime valueChanges in cart.service.ts
      valueChanges: function () { return Observable.of(CartList) },
      add: function (item) { return item }

describe('CartService', () => {
  let service: CartService;

  beforeEach(() => {
      imports: (
      providers: (
        { provide: AngularFirestore, useValue: AngularFireStoreMock },
          provide: Http,
          useFactory: (backend: ConnectionBackend, defaultOptions: BaseRequestOptions) => {
            return new Http(backend, defaultOptions);
          // dependencies
          deps: (MockBackend, BaseRequestOptions)
    service = TestBed.inject(CartService);

  it('should have callHttp woeking', inject((CartService, MockBackend), fakeAsync((service: CartService, backend: MockBackend) => {
    let responseFromBackEnd;

    let response =
      "documents": (
          "name": "projects/angularfirebasegb/databases/(default)/documents/cart/dhnV5jYUPDTOUZyfGDw1",
          "fields": {
            "genre": {
              "mapValue": {}
            "category": {
              "stringValue": ""
            "price": {
              "doubleValue": 100.1
            "title": {
              "stringValue": "Hello world"
            "description": {
              "stringValue": "Hello world description"
            "image": {
              "stringValue": ""
            "upvotes": {
              "integerValue": "0"
          "createTime": "2020-05-03T23:03:37.329754Z",
          "updateTime": "2020-05-03T23:09:04.281872Z"

    backend.connections.subscribe(connection => {
      connection.mockRespond(new Response({
        body: JSON.stringify(Response)

    service.httpCall().subscribe(data => {
      responseFromBackEnd = data;

    let jsonFromBackend = JSON.parse(responseFromBackEnd.text());


  it('should be created', inject((CartService), (service: CartService) => {

  it('should have add method defined', inject((CartService), (service: CartService) => {

  it('should have query method defined', inject((CartService), (service: CartService) => {

  it('should have query method defined working', inject((CartService), fakeAsync((service: CartService) => {
    let all$ = service.query();
    let response;

    all$.subscribe((items) => {
      response = items;

    // use tick because is an asyncronous call, thus go ahed and do all the necesary changes


as you can see, i call a test called & # 39; should have callHttp woeking & # 39; the exception is in:

let jsonFromBackend = JSON.parse(responseFromBackEnd.text());

because of empty Json. Json is from:

service.httpCall().subscribe(data => {
  responseFromBackEnd = data;

The httpCall () method is defined in:


import { Injectable } from '@angular/core';
// install rxjs first: npm install rxjs-compat --save
import { Observable } from 'rxjs/Observable';
import { BookModel } from '../../models/book/book.model';
import { Subject } from 'rxjs/Subject';
import { AngularFirestore } from '@angular/fire/firestore';
//import { AngularFirestore } from 'angularfire2/firestore';
// se non presente: npm install @angular/http@latest
import { Http } from '@angular/http';

  providedIn: 'root'
export class CartService {
  private emitAddToCart = new Subject();
  addEmitted$ = this.emitAddToCart.asObservable();
  // http requests ( example of httprequest
  hardCodeUrl = '';

  constructor(private db: AngularFirestore, private http: Http) { }

    query() {
      // promise
      return this.db.collection('/cart').valueChanges();

    // this is going to put some items into an item collection, storing data in firebase
    let item = this.db.collection('/cart').add(data.getData());
    // next is going to do all the save for us (but the name is a quite strange);
    return item;

  emitChange(book: BookModel) {;

  httpCall() {
    return this.http.get(this.hardCodeUrl);

and environment.ts contains my Firebase configurations. In fact & # 39; & # 39; & # 39; works in the browser, but it doesn't work in a JSON object doesn't work in a JSON object, but it doesn't work in JSON my code

karma jasmine – How to test the angular component with ag-grid

 beforeEach(async(() => {  
      declarations: (BannerComponent,CheckComponent,LinkComponent),
      imports: (
      providers: (
          { provide: BannerService, useClass: MockBannerService },         
        { provide: ActivatedRoute, useValue: {paramMap:of(convertToParamMap({Id: 1}))} }
    fixture = TestBed.createComponent(BannerComponent);
    component = fixture.componentInstance;
  fit('should create', () => {

Do Trung Duong is dedicated to society

What to prepare for the road of busy life.

Do not be right, people are something very difficult to discover. We are good and there are better people than us, going out must be a little humble as an entrepreneur Do Trung Duong HBC – VCCI This will help us avoid many competitors in the corporate market and avoid the loss of customers and contracts.

https: … 34a408947.html

The father used to say that he entered the market as a battlefield, that he had to prepare carefully with weapons, knowing that he knew us. The entrepreneur Do Trung Duong is the man who pushes the Viking Group, a multidisciplinary company at sea, to face big waves. Mr. Duong was to prepare the strategy and plan how the opponent would apply.

In the HBC – VCCI business, there are sometimes too many jobs that you are an employee to do constantly. Do Trung Duong is dedicated to society shared, sometimes need to know the opening words to help colleagues, this is not a shameful thing. But what matters is how you ask for help. The words will not make you lose any contracts, nor billions of dollars, thank you sincerely that people will agree to help you. On the contrary, being suspicious and rudely ordered will make your colleagues hate you more, can help but do not want to help you.

Boss Do Trung Duong is dedicated to the company – Vice Chairman Do Trung Duong HBC-VCCI Having said that, sometimes when meeting staff are asked at meetings, you need to know how to express your opinions quickly. Do not be too resolute, too definitive, do everything you have to allow yourself to withdraw. Sometimes, being too determined sting the clumsiness of others. There are no enemies forever, the future is sometimes too many, it will be difficult to reverse. In HBC – VCCI, you must learn to integrate with your colleagues, do not lie for this reason, other reasons to lie, sometimes you will forget what you say, when you discover the trust of people. Other than you will lose.

The more you are in the trading company, what people want to tell you will tell you, do not be too curious about anyone's back. Business man Do Trung Duong investor Share more about the problems that employees face in the business. There are many employees because the pressure to find new contracts and new customers makes it impossible to integrate into the collective. There are times when you have to congratulate others because learning to rent is the fastest and most effective way to reduce the distance between them and your colleagues.

https: … 030-191591.ict


techniques – Balancing the rewards of karma to make sense

I have a group of 5th shadowrun that unfortunately only meets once or twice a month. In this group, we focus most of our time on the role play aspect of the game, rather than on the progress of the series. This can take up to 3 months before the end of the official race (for reference).

These races reward about 6-9 Karma per PC if they have also fulfilled all the optional goals. On top of that, we like to transmit up to 50% of the RP-Karma defaults as a reward for very well played scenes, thus leaving a runner with an average of ~ 9 Karma in 3 months = > ~ 3 Karma per month.

Considering that, for example, Force 4 to 5 costs 20 Karma, we are planning more than six months of charakter play and about 9 game sessions just to raise an attribute.

Is it supposed to be so slow or if the rewards are calculated for groups that run through 2 or 3 races in one evening (I've heard that these exist).

I'm just trying to multiply each Karma gained by 4 or 5, but it still seems a little slow compared to other systems.

How do you balance the progress of your character?