MapsApiLoader.load not recognised in karma test
See original GitHub issueI’m trying to mock the call to the maps api loader but karma keeps failing saying that load() is not recognised
Test:
describe('CommuteDetailsModalComponent', () => {
let component: CommuteDetailsModalComponent;
let fixture: ComponentFixture<CommuteDetailsModalComponent>;
let mapsApiLoader;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [CommuteDetailsModalComponent],
providers: [
MapsAPILoader
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(CommuteDetailsModalComponent);
component = fixture.componentInstance;
mapsApiLoader = fixture.debugElement.injector.get(MapsAPILoader);
spyOn(mapsApiLoader, 'load').and.callFake(() => {
return true;
});
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
Result :
Error: <spyOn> : load() method does not exist
Usage: spyOn(<object>, <methodName>)
Any ideas what I’m missing?
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
MapsApiLoader.load not recognised in karma test · Issue #1295
I'm trying to mock the call to the maps api loader but karma keeps failing saying that load() is not recognised Test: ...
Read more >Developers - MapsApiLoader.load not recognised in karma test -
Coming soon: A brand new website interface for an even better experience!
Read more >Google maps won't load in angular project because of Error
I have tried to provide MapsApiLoader in admin.module. But this does not work because a typescript error is thrown.
Read more >Overview | Maps JavaScript API - Google Developers
Get started with the Google Maps JavaScript API. View a simple example, learn the concepts, and create custom maps for your site.
Read more >nullinjectorerror: no provider for mapsapiloader! angular 2
It is working fine natively on my phone but not in any browser in PRODUCTION. I also could add the InAppBrowser to the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
To add to this, you should be able to mock the MapsAPILoader with a mock such as:
You shouldn’t have to use NO_ERRORS_SCHEMA as a result.
Hi guys,
Try:
beforeEach(async(() => { TestBed.configureTestingModule({ imports: [..., AgmCoreModule.forRoot()], declarations: [..., AgmMarkerCluster] }) .compileComponents(); }));
Works for me.