Skip to content

Commit b382b60

Browse files
committed
test(material/icon): account for API changes
* Replaces a deprecated API in the icon's tests. * Removes a test that isn't relevant anymore since the HTTP provider is guaranteed to exist.
1 parent 0efe87f commit b382b60

File tree

1 file changed

+14
-47
lines changed

1 file changed

+14
-47
lines changed

src/material/icon/icon.spec.ts

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import {wrappedErrorMessage} from '@angular/cdk/testing/private';
21
import {
3-
HttpClientTestingModule,
2+
provideHttpClientTesting,
43
HttpTestingController,
54
TestRequest,
65
} from '@angular/common/http/testing';
@@ -9,7 +8,7 @@ import {TestBed, fakeAsync, tick, waitForAsync} from '@angular/core/testing';
98
import {DomSanitizer, SafeHtml, SafeResourceUrl} from '@angular/platform-browser';
109
import {FAKE_SVGS} from './fake-svgs';
1110
import {MatIcon} from './icon';
12-
import {MatIconRegistry, getMatIconNoHttpProviderError} from './icon-registry';
11+
import {MatIconRegistry} from './icon-registry';
1312
import {MAT_ICON_DEFAULT_OPTIONS, MAT_ICON_LOCATION, MatIconModule} from './index';
1413

1514
/** Returns the CSS classes assigned to an element as a sorted array. */
@@ -65,7 +64,6 @@ describe('MatIcon', () => {
6564

6665
TestBed.configureTestingModule({
6766
imports: [
68-
HttpClientTestingModule,
6967
MatIconModule,
7068
IconWithColor,
7169
IconWithLigature,
@@ -80,6 +78,7 @@ describe('MatIcon', () => {
8078
BlankIcon,
8179
],
8280
providers: [
81+
provideHttpClientTesting(),
8382
{
8483
provide: MAT_ICON_LOCATION,
8584
useValue: {getPathname: () => fakePath},
@@ -1358,38 +1357,6 @@ describe('MatIcon', () => {
13581357
}
13591358
});
13601359

1361-
describe('MatIcon without HttpClientModule', () => {
1362-
let iconRegistry: MatIconRegistry;
1363-
let sanitizer: DomSanitizer;
1364-
1365-
@Component({
1366-
template: `<mat-icon [svgIcon]="iconName"></mat-icon>`,
1367-
imports: [MatIcon],
1368-
})
1369-
class IconFromSvgName {
1370-
iconName: string | undefined = '';
1371-
}
1372-
1373-
beforeEach(waitForAsync(() => {
1374-
iconRegistry = TestBed.inject(MatIconRegistry);
1375-
sanitizer = TestBed.inject(DomSanitizer);
1376-
}));
1377-
1378-
it('should throw an error when trying to load a remote icon', () => {
1379-
const expectedError = wrappedErrorMessage(getMatIconNoHttpProviderError());
1380-
1381-
expect(() => {
1382-
iconRegistry.addSvgIcon('fido', sanitizer.bypassSecurityTrustResourceUrl('dog.svg'));
1383-
1384-
const fixture = TestBed.createComponent(IconFromSvgName);
1385-
1386-
fixture.componentInstance.iconName = 'fido';
1387-
fixture.changeDetectorRef.markForCheck();
1388-
fixture.detectChanges();
1389-
}).toThrowError(expectedError);
1390-
});
1391-
});
1392-
13931360
describe('MatIcon with default options', () => {
13941361
it('should be able to configure color globally', fakeAsync(() => {
13951362
const fixture = createComponent(IconWithLigature, [
@@ -1457,23 +1424,23 @@ describe('MatIcon with default options', () => {
14571424

14581425
@Component({
14591426
template: `<mat-icon>{{iconName}}</mat-icon>`,
1460-
imports: [HttpClientTestingModule, MatIconModule],
1427+
imports: [MatIconModule],
14611428
})
14621429
class IconWithLigature {
14631430
iconName = '';
14641431
}
14651432

14661433
@Component({
14671434
template: `<mat-icon [fontIcon]="iconName"></mat-icon>`,
1468-
imports: [HttpClientTestingModule, MatIconModule],
1435+
imports: [MatIconModule],
14691436
})
14701437
class IconWithLigatureByAttribute {
14711438
iconName = '';
14721439
}
14731440

14741441
@Component({
14751442
template: `<mat-icon [color]="iconColor">{{iconName}}</mat-icon>`,
1476-
imports: [HttpClientTestingModule, MatIconModule],
1443+
imports: [MatIconModule],
14771444
})
14781445
class IconWithColor {
14791446
iconName = '';
@@ -1482,7 +1449,7 @@ class IconWithColor {
14821449

14831450
@Component({
14841451
template: `<mat-icon [fontSet]="fontSet" [fontIcon]="fontIcon"></mat-icon>`,
1485-
imports: [HttpClientTestingModule, MatIconModule],
1452+
imports: [MatIconModule],
14861453
})
14871454
class IconWithCustomFontCss {
14881455
fontSet = '';
@@ -1491,21 +1458,21 @@ class IconWithCustomFontCss {
14911458

14921459
@Component({
14931460
template: `<mat-icon [svgIcon]="iconName"></mat-icon>`,
1494-
imports: [HttpClientTestingModule, MatIconModule],
1461+
imports: [MatIconModule],
14951462
})
14961463
class IconFromSvgName {
14971464
iconName: string | undefined = '';
14981465
}
14991466

15001467
@Component({
15011468
template: '<mat-icon aria-hidden="false">face</mat-icon>',
1502-
imports: [HttpClientTestingModule, MatIconModule],
1469+
imports: [MatIconModule],
15031470
})
15041471
class IconWithAriaHiddenFalse {}
15051472

15061473
@Component({
15071474
template: `@if (showIcon) {<mat-icon [svgIcon]="iconName">{{iconName}}</mat-icon>}`,
1508-
imports: [HttpClientTestingModule, MatIconModule],
1475+
imports: [MatIconModule],
15091476
})
15101477
class IconWithBindingAndNgIf {
15111478
iconName = 'fluffy';
@@ -1514,31 +1481,31 @@ class IconWithBindingAndNgIf {
15141481

15151482
@Component({
15161483
template: `<mat-icon [inline]="inline">{{iconName}}</mat-icon>`,
1517-
imports: [HttpClientTestingModule, MatIconModule],
1484+
imports: [MatIconModule],
15181485
})
15191486
class InlineIcon {
15201487
inline = false;
15211488
}
15221489

15231490
@Component({
15241491
template: `<mat-icon [svgIcon]="iconName"><div>Hello</div></mat-icon>`,
1525-
imports: [HttpClientTestingModule, MatIconModule],
1492+
imports: [MatIconModule],
15261493
})
15271494
class SvgIconWithUserContent {
15281495
iconName: string | undefined = '';
15291496
}
15301497

15311498
@Component({
15321499
template: '<mat-icon [svgIcon]="iconName">house</mat-icon>',
1533-
imports: [HttpClientTestingModule, MatIconModule],
1500+
imports: [MatIconModule],
15341501
})
15351502
class IconWithLigatureAndSvgBinding {
15361503
iconName: string | undefined;
15371504
}
15381505

15391506
@Component({
15401507
template: `<mat-icon></mat-icon>`,
1541-
imports: [HttpClientTestingModule, MatIconModule],
1508+
imports: [MatIconModule],
15421509
})
15431510
class BlankIcon {
15441511
@ViewChild(MatIcon) icon: MatIcon;

0 commit comments

Comments
 (0)