如何对导入GooglePlaceModule的组件进行单元测试

问题描述

我遇到以下错误: 失败:未定义google 在 在GooglePlaceDirective.isGoogleLibExists(http:// localhost:9876 / karma_webpack / node_modules / ngx-google-places-autocomplete / ivy_ngcc / bundles / ngx-google-places-autocomplete .umd.js:41:1)

我正在从'ngx-google-places-autocomplete'导入import {GooglePlaceModule}; 在module.ts中。

这是我的规格文件

import { async,ComponentFixture,Testbed } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';
import { FormsModule,ReactiveFormsModule } from '@angular/forms';
import { AddItineraryPage } from './add-itinerary.page';
import { RouterTestingModule } from '@angular/router/testing';
import { GooglePlaceModule } from 'ngx-google-places-autocomplete';

describe('AddItineraryPage',() => {
  let component: AddItineraryPage;
  let fixture: ComponentFixture<AddItineraryPage>;

  beforeEach(async(() => {
    Testbed.configureTestingModule({
      declarations: [ AddItineraryPage ],imports: [IonicModule.forRoot(),FormsModule,ReactiveFormsModule,RouterTestingModule,GooglePlaceModule]
    }).compileComponents();

    fixture = Testbed.createComponent(AddItineraryPage);
    component = fixture.componentInstance;
    fixture.detectChanges();
  }));

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

任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)