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 
    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 Zone.run (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:
–cart.service.spec.ts–

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 './cart.services.mock';
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: "angularfirebasegb.firebaseapp.com",
    databaseURL: "https://angularfirebasegb.firebaseio.com",
    projectId: "angularfirebasegb",
    storageBucket: "angularfirebasegb.appspot.com",
    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(() => {
    TestBed.configureTestingModule({
      imports: (
        AngularFireModule.initializeApp(environment.firebase),
        AngularFirestoreModule
      ),
      providers: (
        CartService,
        { provide: AngularFirestore, useValue: AngularFireStoreMock },
        BaseRequestOptions,
        MockBackend,
        {
          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": "https://image.shutterstock.com/image-photo/white-transparent-leaf-on-mirror-260nw-1029171697.jpg"
            },
            "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;
    });

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

    expect(jsonFromBackend).toEqual(response);
  }))
  );

  it('should be created', inject((CartService), (service: CartService) => {
    expect(service).toBeTruthy();
  }));

  it('should have add method defined', inject((CartService), (service: CartService) => {
    expect(service.add).toBeTruthy();
  }));

  it('should have query method defined', inject((CartService), (service: CartService) => {
    expect(service.query).toBeTruthy();
  }));

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

    // NOMINARE LE VARIABILI DI TIPO OBSERVABLE CON IL '$', PER CONVENZIONE. TUTTAVIA NON E' OBBLIGATORIO
    all$.subscribe((items) => {
      response = items;
    });

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

    expect(response).toBe(CartList);
  })));
});

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:

–cart.service.ts–

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';


@Injectable({
  providedIn: 'root'
})
export class CartService {
  private emitAddToCart = new Subject();
  addEmitted$ = this.emitAddToCart.asObservable();
  // http requests (https://firebase.google.com/docs/firestore/use-rest-api) example of httprequest
  hardCodeUrl = 'https://firestore.googleapis.com/v1/projects/angularfirebasegb/databases/(default)/documents/cart?key=AIzaSyDNW48hAmvH8eAZpbeflRKb0khY5Blzsqg';


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

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

  add(data){
    // 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)
    this.emitAddToCart.next(item);
    return item;
  }

  emitChange(book: BookModel) {
    this.emitAddToCart.next(book);
  }

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

and environment.ts contains my Firebase configurations. In fact & # 39; & # 39; https://firestore.googleapis.com/v1/projects/angularfirebasegb/databases/(default)/documents/cart?key=AIzaSyDNW48hAmvH8eAZpbeflRKb0khY5Blzsqg & # 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(() => {  
    TestBed.configureTestingModule({
      declarations: (BannerComponent,CheckComponent,LinkComponent),
      imports: (
        RouterTestingModule, 
        FormsModule,
        HttpClientModule,  
        BsDatepickerModule.forRoot(),
        DatepickerModule.forRoot(),
        AgGridModule.withComponents((CheckComponent,LinkComponent))),
      providers: (
          { provide: BannerService, useClass: MockBannerService },         
        { provide: ActivatedRoute, useValue: {paramMap:of(convertToParamMap({Id: 1}))} }
    ),
      schemas: (CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA)
    })
    .compileComponents();
    fixture = TestBed.createComponent(BannerComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
}));
  fit('should create', () => {
    fixture.detectChanges();
    expect(component).toBeTruthy();
  });

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: eva.vn/doi-song-xa-hoi/doanh-n … 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: ictnews.vn/trang-chinh/trang-n … 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?