Невозможно получить свойство unuseGeometry с неопределенной или пустой ссылкой - PullRequest
0 голосов
/ 11 мая 2019

Я делаю автоматический тест для моего углового приложения, и я получил эту ошибку: Невозможно получить свойство 'unuseGeometry' с неопределенным или пустым указанием .Я не знаю, в чем дело, для проверки я использую браузер Edge.

it('should call goToInitialMenu()', () => {
    spyOn(component, 'goToInitialMenu');
    component.goToInitialMenu();
    fixture.whenStable().then(()=> {
      expect(component.goToInitialMenu).toHaveBeenCalled();
    });
});

Полный тестовый файл:

import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';
import { SinglePlayerMenuComponent } from './single-player-menu.component';
import { HttpClientModule } from '@angular/common/http';

fdescribe('SinglePlayerMenuComponent', () => {
  let component: SinglePlayerMenuComponent;
  let fixture: ComponentFixture<SinglePlayerMenuComponent>;

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ SinglePlayerMenuComponent ],
      schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
      providers: [SinglePlayerMenuComponent],
      imports: [ HttpClientModule ],
    })
    .compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(SinglePlayerMenuComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

  it('should call goToInitialMenu()', () => {
    spyOn(component, 'goToInitialMenu');
    component.goToInitialMenu();
    fixture.whenStable().then(()=> {
      expect(component.goToInitialMenu).toHaveBeenCalled();
    });
  });
});

Это файл компонента:

import { Component, OnInit, OnDestroy } from '@angular/core';
import { Song } from 'src/app/shared/song/song.model';
import { SceneOrchestratorService } from 'src/app/services/scene-orchestrator.service';
import { Scene } from 'src/app/shared/scene/scene.enum';
import { SongService } from 'src/app/services/song.service';
import { Subscription } from 'rxjs';

@Component({
  selector: 'a-single-player-menu',
  templateUrl: './single-player-menu.component.html',
  styleUrls: ['./single-player-menu.component.css']
})
export class SinglePlayerMenuComponent implements OnInit, OnDestroy {

  private _songSrvSubscription: Subscription;
  constructor(private _sceneOrchestratorSrv: SceneOrchestratorService,
              private _songSrv: SongService) { }

  private _songs: Song[];
  private _selectedSong: Song;

  ngOnInit() {
    this._songSrvSubscription = this._songSrv.getTopRaitedSongsList().subscribe(
      (result: Song[]) => {
        this.songs = result;
      });
  }

  ngOnDestroy() {
    if (this._songSrvSubscription != undefined) {
      this._songSrvSubscription.unsubscribe();
    }
  }

  get songs(): Song[] {
    return this._songs;
  }

  set songs(songs: Song[]) {
    console.log(songs)
    this._songs = songs;
  }

  get selectedSong() {
    return this._selectedSong;
  }

  set selectedSong(songSelected: Song) {
    this._selectedSong = songSelected;
  }

  selectTheSong(song: Song) {
    this._selectedSong = song;
  }

  goToInitialMenu() {
    this._sceneOrchestratorSrv.actualScene = Scene.initialMenu;
  }
}

У меня такой же код в другом компоненте, и он работает нормально, я не знаю, почему в этом компоненте я получил эту ошибку.

1 Ответ

0 голосов
/ 12 мая 2019

В конце концов решение было добавить службы в

app.module.ts

и тоже добавить

HttpClientModule, HttpClient

поставщикам и импорте

import { BrowserModule } from '@angular/platform-browser';
import { RouterModule, Routes } from '@angular/router';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA } from '@angular/core';

import { AppComponent } from './app.component';
import { MenuComponent } from './menu/menu.component';
import { GameComponent } from './game/game.component';
import { SinglePlayerMenuComponent } from './menu/single-player-menu/single-player-menu.component';
import { PartyMenuComponent } from './menu/party-menu/party-menu.component';
import { HowToPlayComponent } from './menu/how-to-play/how-to-play.component';
import { CreditsComponent } from './menu/credits/credits.component';
import { SongService } from '../services/song.service';
import { BeatsaverAPIService } from '../services/beatsaverAPI.service';

const appRoutes: Routes = [
  { path: '/game', component: GameComponent },
  { path: '/menu',      component: MenuComponent },
  { path: '/singlePlayerMenu',      component: SinglePlayerMenuComponent },
  { path: '/',      component: AppComponent },
];

@NgModule({
  declarations: [
    AppComponent,
    MenuComponent,
    GameComponent,
    SinglePlayerMenuComponent,
    PartyMenuComponent,
    HowToPlayComponent,
    CreditsComponent,
  ],
  imports: [
    BrowserModule,
    HttpClientModule
  ],
  providers: [HttpClientModule, HttpClient, SongService, BeatsaverAPIService],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA]
})
export class AppModule { }

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...