我在尝试将Ionic Native Geolocation作为依赖项进行测试时收到以下错误:
Failed: R3InjectorError(DynamicTestModule)[Geolocation -> Geolocation]:
NullInjectorError: No provider for Geolocation!
error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'Geolocation', 'Geolocation' ] })
NullInjectorError: R3InjectorError(DynamicTestModule)[Geolocation -> Geolocation]:
NullInjectorError: No provider for Geolocation!
测试设置如下所示:
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { IonicModule, IonItem, Platform } from '@ionic/angular';
import { FoloLocation } from '../models/folo-location';
import { Geolocation } from '@ionic-native/geolocation/ngx';
import { HomePage } from './home.page';
describe('HomePage', () => {
let component: HomePage;
let fixture: ComponentFixture<HomePage>;
let platform: Platform;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ HomePage ],
imports: [IonicModule.forRoot()],
providers: [
Geolocation
]
}).compileComponents();
fixture = TestBed.createComponent(HomePage);
component = fixture.componentInstance;
platform = TestBed.inject(Platform);
fixture.detectChanges();
}));
我也试过提供一个模拟,但无济于事。
1条答案
按热度按时间ghg1uchk1#
显然从这个错误:
看起来
Geolocation
依赖于Geolocation
。你能试着做以下几件事吗?
我们为
Geolocation
服务提供了一个空对象。请查看您现在是否看到其他错误,如果看到,则必须模拟您使用的Geolocation
的公共方法。