mirror of
https://github.com/ionic-team/ionicons.git
synced 2026-12-01 16:56:28 +01:00
fix(icon): mapping same icon does not warn (#1279)
This commit is contained in:
@@ -126,27 +126,38 @@ describe('addIcons', () => {
|
||||
expect(getIconMap().get('myCoolIcon')).toEqual(logoIonitron);
|
||||
});
|
||||
|
||||
it('should not warn when mapping the same icon twice', () => {
|
||||
const spy = jest.spyOn(console, 'warn');
|
||||
|
||||
const myIcon = 'my-icon';
|
||||
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
|
||||
addIcons({ myIcon });
|
||||
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
|
||||
addIcons({ myIcon });
|
||||
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should not overwrite icons', () => {
|
||||
const spy = jest.spyOn(console, 'warn');
|
||||
|
||||
const logoA = 'logo a';
|
||||
const logoB = 'logo b';
|
||||
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
|
||||
expect(getIconMap().get('logo-a')).toEqual(undefined);
|
||||
|
||||
addIcons({ 'logo-a': logoB, logoA });
|
||||
|
||||
expect(getIconMap().get('logo-a')).toEqual(logoB);
|
||||
expect(getIconMap().get('logoA')).toEqual(logoA);
|
||||
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('passing kebab case key should not generate a camel case key', () => {
|
||||
const logoIonitron = 'stubbed data';
|
||||
|
||||
expect(getIconMap().get('kebab-key')).toEqual(undefined);
|
||||
expect(getIconMap().get('kebabKey')).toEqual(undefined);
|
||||
|
||||
addIcons({ 'kebab-key': logoIonitron });
|
||||
|
||||
expect(getIconMap().get('kebab-key')).toEqual(logoIonitron);
|
||||
expect(getIconMap().get('kebabKey')).toEqual(undefined);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -40,10 +40,17 @@ export const addIcons = (icons: { [name: string]: string; }) => {
|
||||
|
||||
const addToIconMap = (name: string, data: any) => {
|
||||
const map = getIconMap();
|
||||
|
||||
const existingIcon = map.get(name);
|
||||
|
||||
if (map.get(name) === undefined) {
|
||||
if (existingIcon === undefined) {
|
||||
map.set(name, data);
|
||||
} else {
|
||||
|
||||
/**
|
||||
* Importing and defining the same icon reference
|
||||
* multiple times should not yield a warning.
|
||||
*/
|
||||
} else if (existingIcon !== data) {
|
||||
console.warn(`[Ionicons Warning]: Multiple icons were mapped to name "${name}". Ensure that multiple icons are not mapped to the same icon name.`)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user