2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-12 13:47:49 +00:00

chore: test loaders with reserved keyword

This commit is contained in:
Vjacheslav Trushkin 2024-11-03 21:22:49 +02:00
parent b5e6a4db1d
commit d070e3a50a
2 changed files with 23 additions and 13 deletions

View File

@ -222,7 +222,7 @@ describe('Rendering icon', () => {
test('custom loader', () => { test('custom loader', () => {
return new Promise((fulfill, reject) => { return new Promise((fulfill, reject) => {
const prefix = nextPrefix(); const prefix = nextPrefix();
const name = 'render-test'; const name = 'constructor'; // Use reserved name to test objects
const iconName = `@${provider}:${prefix}:${name}`; const iconName = `@${provider}:${prefix}:${name}`;
const className = `iconify iconify--${prefix} iconify--${provider}`; const className = `iconify iconify--${prefix} iconify--${provider}`;
let onLoadCalled = false; let onLoadCalled = false;

View File

@ -42,6 +42,10 @@ describe('Testing API loadIcons', () => {
icon_2: { icon_2: {
body: '<path d="" />', body: '<path d="" />',
}, },
// Use reserved keyword that can break objects not created with Object.create(null)
constructor: {
body: '<path d="" />',
},
}, },
}); });
}); });
@ -64,6 +68,7 @@ describe('Testing API loadIcons', () => {
expect(listIcons(provider, prefix)).toEqual([ expect(listIcons(provider, prefix)).toEqual([
`@${provider}:${prefix}:icon1`, `@${provider}:${prefix}:icon1`,
`@${provider}:${prefix}:icon_2`, `@${provider}:${prefix}:icon_2`,
`@${provider}:${prefix}:constructor`,
]); ]);
} catch (err) { } catch (err) {
reject(err); reject(err);
@ -101,6 +106,10 @@ describe('Testing API loadIcons', () => {
Icon_1: { Icon_1: {
body: '<path d="" />', body: '<path d="" />',
}, },
// Use reserved keyword that can break objects not created with Object.create(null)
constructor: {
body: '<path d="" />',
},
}, },
}; };
}, },
@ -121,6 +130,7 @@ describe('Testing API loadIcons', () => {
// Check storage // Check storage
expect(listIcons(provider, prefix)).toEqual([ expect(listIcons(provider, prefix)).toEqual([
`@${provider}:${prefix}:Icon_1`, `@${provider}:${prefix}:Icon_1`,
`@${provider}:${prefix}:constructor`,
]); ]);
} catch (err) { } catch (err) {
reject(err); reject(err);
@ -143,7 +153,7 @@ describe('Testing API loadIcons', () => {
(icons, requestedPrefix, requestedProvider) => { (icons, requestedPrefix, requestedProvider) => {
try { try {
// Check params // Check params
expect(icons).toEqual(['icon1']); expect(icons).toEqual(['constructor']);
expect(requestedPrefix).toBe(prefix1); expect(requestedPrefix).toBe(prefix1);
expect(requestedProvider).toBe(provider); expect(requestedProvider).toBe(provider);
} catch (err) { } catch (err) {
@ -155,7 +165,7 @@ describe('Testing API loadIcons', () => {
return { return {
prefix: prefix1, prefix: prefix1,
icons: { icons: {
icon1: { constructor: {
body: '<path d="" />', body: '<path d="" />',
}, },
}, },
@ -203,7 +213,7 @@ describe('Testing API loadIcons', () => {
// Load icons // Load icons
loadIcons( loadIcons(
[ [
`${provider}:${prefix1}:icon1`, `${provider}:${prefix1}:constructor`,
`${provider}:${prefix2}:Icon_2`, `${provider}:${prefix2}:Icon_2`,
`${provider}:${prefix2}:BadIcon`, `${provider}:${prefix2}:BadIcon`,
], ],
@ -219,7 +229,7 @@ describe('Testing API loadIcons', () => {
{ {
provider, provider,
prefix: prefix1, prefix: prefix1,
name: 'icon1', name: 'constructor',
}, },
{ {
provider, provider,
@ -237,7 +247,7 @@ describe('Testing API loadIcons', () => {
// Check storage // Check storage
expect(listIcons(provider, prefix1)).toEqual([ expect(listIcons(provider, prefix1)).toEqual([
`@${provider}:${prefix1}:icon1`, `@${provider}:${prefix1}:constructor`,
]); ]);
expect(listIcons(provider, prefix2)).toEqual([ expect(listIcons(provider, prefix2)).toEqual([
`@${provider}:${prefix2}:Icon_1`, `@${provider}:${prefix2}:Icon_1`,
@ -265,7 +275,7 @@ describe('Testing API loadIcons', () => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
// Check params // Check params
expect(name).toBe('icon1'); expect(name).toBe('constructor');
expect(requestedPrefix).toBe(prefix); expect(requestedPrefix).toBe(prefix);
expect(requestedProvider).toBe(provider); expect(requestedProvider).toBe(provider);
} catch (err) { } catch (err) {
@ -284,7 +294,7 @@ describe('Testing API loadIcons', () => {
); );
// Load icon // Load icon
loadIcon(provider + ':' + prefix + ':icon1') loadIcon(provider + ':' + prefix + ':constructor')
.then((data) => { .then((data) => {
try { try {
// Test response // Test response
@ -295,7 +305,7 @@ describe('Testing API loadIcons', () => {
// Check storage // Check storage
expect(listIcons(provider, prefix)).toEqual([ expect(listIcons(provider, prefix)).toEqual([
`@${provider}:${prefix}:icon1`, `@${provider}:${prefix}:constructor`,
]); ]);
} catch (err) { } catch (err) {
reject(err); reject(err);
@ -314,7 +324,7 @@ describe('Testing API loadIcons', () => {
const prefix2 = nextPrefix(); const prefix2 = nextPrefix();
const iconsToTest: Record<string, Set<string>> = { const iconsToTest: Record<string, Set<string>> = {
[prefix1]: new Set(['icon1']), [prefix1]: new Set(['constructor']),
[prefix2]: new Set(['Icon_2', 'BadIcon']), [prefix2]: new Set(['Icon_2', 'BadIcon']),
}; };
@ -375,7 +385,7 @@ describe('Testing API loadIcons', () => {
// Load icons // Load icons
loadIcons( loadIcons(
[ [
`${provider}:${prefix1}:icon1`, `${provider}:${prefix1}:constructor`,
`${provider}:${prefix2}:Icon_2`, `${provider}:${prefix2}:Icon_2`,
`${provider}:${prefix2}:BadIcon`, `${provider}:${prefix2}:BadIcon`,
], ],
@ -391,7 +401,7 @@ describe('Testing API loadIcons', () => {
{ {
provider, provider,
prefix: prefix1, prefix: prefix1,
name: 'icon1', name: 'constructor',
}, },
{ {
provider, provider,
@ -409,7 +419,7 @@ describe('Testing API loadIcons', () => {
// Check storage // Check storage
expect(listIcons(provider, prefix1)).toEqual([ expect(listIcons(provider, prefix1)).toEqual([
`@${provider}:${prefix1}:icon1`, `@${provider}:${prefix1}:constructor`,
]); ]);
expect(listIcons(provider, prefix2)).toEqual([ expect(listIcons(provider, prefix2)).toEqual([
`@${provider}:${prefix2}:Icon_2`, `@${provider}:${prefix2}:Icon_2`,