【发布时间】:2023-02-16 21:30:14
【问题描述】:
我正在尝试为使用 GooglePlaceModule 的组件编写单元测试。我不断收到以下错误的失败测试:
Failed: Google maps library can not be found
在搜索解决方案时,我在网上尝试了 2 件事:
我根据建议在 karma.conf.js 文件中添加了这一行:
files: [
'https://maps.googleapis.com/maps/api/js?key=<key>=places&language=enhttps://maps.google.com/maps/api/js?key=<removed>&libraries=places'
],
那没有用。
这是我的规格文件:
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';
import { ProfileFormComponent } from './profile-form.component';
import { ReactiveFormsModule } from '@angular/forms';
import { GooglePlaceModule } from 'ngx-google-places-autocomplete';
describe('ProfileFormComponent', () => {
let component: ProfileFormComponent;
let fixture: ComponentFixture<ProfileFormComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ ProfileFormComponent ],
imports: [IonicModule.forRoot(), ReactiveFormsModule, GooglePlaceModule]
}).compileComponents();
window['google'] = {
maps: {
Maps: () => {}
}
};
fixture = TestBed.createComponent(ProfileFormComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should create', () => {
expect(component).toBeTruthy();
});
});
到目前为止这是非常基本的,我只是想让最小的通过。
【问题讨论】:
-
嗨@D.Hodges,我和你的情况相似。你能解决这个问题吗?
标签: javascript unit-testing karma-jasmine google-places-api