Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(common): add
provideLocationMocks()
function to provide Locati…
…on 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
- Loading branch information
1 parent
4fde292
commit c0c7efa
Showing
11 changed files
with
166 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/common/test/location/provide_location_mocks_spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* @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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* @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 {Provider} from '@angular/core'; | ||
|
||
import {SpyLocation} from './location_mock'; | ||
import {MockLocationStrategy} from './mock_location_strategy'; | ||
|
||
/** | ||
* Returns mock providers for the `Location` and `LocationStrategy` classes. | ||
* The mocks are helpful in tests to fire simulated location events. | ||
* | ||
* @developerPreview | ||
* @publicApi | ||
*/ | ||
export function provideLocationMocks(): Provider[] { | ||
return [ | ||
{provide: Location, useClass: SpyLocation}, | ||
{provide: LocationStrategy, useClass: MockLocationStrategy}, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.