Files
angular__angular/packages/common/test/location/provide_location_mocks_spec.ts
Andrew Kushnir c0c7efaf7c feat(common): add provideLocationMocks() function to provide Location mocks (#47674)
This commit adds the `provideLocationMocks()` function that returns mocks for the `Location` and `LocationStrategy` classes. This function can be used in tests to configure an environment where it's possible to fire simulated location events (helpful when testing Router configuration).

PR Close #47674
2022-10-10 19:42:11 +00:00

24 lines
840 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Location, LocationStrategy} from '@angular/common';
import {MockLocationStrategy, provideLocationMocks, SpyLocation} from '@angular/common/testing';
import {TestBed} from '@angular/core/testing';
describe('provideLocationMocks() function', () => {
it('should mock Location and LocationStrategy classes', () => {
TestBed.configureTestingModule({providers: [provideLocationMocks()]});
const location = TestBed.inject(Location);
const locationStrategy = TestBed.inject(LocationStrategy);
expect(location).toBeInstanceOf(SpyLocation);
expect(locationStrategy).toBeInstanceOf(MockLocationStrategy);
});
});