mirror of
https://github.com/iconify/iconify.git
synced 2024-12-13 22:18:24 +00:00
332 lines
4.4 KiB
TypeScript
332 lines
4.4 KiB
TypeScript
import { validateIconSet } from '../lib/icon-set/validate';
|
|
|
|
describe('Testing validating alias', () => {
|
|
test('Empty', () => {
|
|
expect(
|
|
validateIconSet({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {},
|
|
})
|
|
).toEqual({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {},
|
|
});
|
|
|
|
// Fix it
|
|
expect(
|
|
validateIconSet(
|
|
{
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {},
|
|
},
|
|
{ fix: true }
|
|
)
|
|
).toEqual({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
test('Null', (done) => {
|
|
try {
|
|
validateIconSet({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: null,
|
|
});
|
|
done('Expected to throw error when aliases is null');
|
|
} catch (err) {
|
|
//
|
|
}
|
|
|
|
// Fix it
|
|
expect(
|
|
validateIconSet(
|
|
{
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: null,
|
|
},
|
|
{ fix: true }
|
|
)
|
|
).toEqual({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
});
|
|
|
|
done();
|
|
});
|
|
|
|
test('Invalid parent', (done) => {
|
|
try {
|
|
const result = validateIconSet({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {
|
|
baz: {
|
|
parent: 'missing',
|
|
},
|
|
},
|
|
});
|
|
done(
|
|
'Expected to throw error when alias has missing parent, got ' +
|
|
JSON.stringify(result)
|
|
);
|
|
} catch (err) {
|
|
//
|
|
}
|
|
|
|
// Fix it
|
|
expect(
|
|
validateIconSet(
|
|
{
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {
|
|
baz: {
|
|
parent: 'missing',
|
|
},
|
|
},
|
|
},
|
|
{ fix: true }
|
|
)
|
|
).toEqual({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
});
|
|
|
|
done();
|
|
});
|
|
|
|
test('Invalid parent, 2 levels', (done) => {
|
|
try {
|
|
const result = validateIconSet({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {
|
|
baz: {
|
|
parent: 'missing',
|
|
},
|
|
baz2: {
|
|
parent: 'baz',
|
|
},
|
|
},
|
|
});
|
|
done(
|
|
'Expected to throw error when alias has missing parent, got ' +
|
|
JSON.stringify(result)
|
|
);
|
|
} catch (err) {
|
|
//
|
|
}
|
|
|
|
// Fix it
|
|
expect(
|
|
validateIconSet(
|
|
{
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {
|
|
baz: {
|
|
parent: 'missing',
|
|
},
|
|
baz2: {
|
|
parent: 'baz',
|
|
},
|
|
},
|
|
},
|
|
{ fix: true }
|
|
)
|
|
).toEqual({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
});
|
|
|
|
done();
|
|
});
|
|
|
|
test('Invalid parent, 2 levels, reverse order', (done) => {
|
|
try {
|
|
const result = validateIconSet({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {
|
|
baz: {
|
|
parent: 'baz2',
|
|
},
|
|
baz2: {
|
|
parent: 'missing',
|
|
},
|
|
},
|
|
});
|
|
done(
|
|
'Expected to throw error when alias has missing parent, got ' +
|
|
JSON.stringify(result)
|
|
);
|
|
} catch (err) {
|
|
//
|
|
}
|
|
|
|
// Fix it
|
|
expect(
|
|
validateIconSet(
|
|
{
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {
|
|
baz: {
|
|
parent: 'baz2',
|
|
},
|
|
baz2: {
|
|
parent: 'missing',
|
|
},
|
|
},
|
|
},
|
|
{ fix: true }
|
|
)
|
|
).toEqual({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
});
|
|
|
|
done();
|
|
});
|
|
|
|
test('Parent loop', (done) => {
|
|
try {
|
|
const result = validateIconSet({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {
|
|
baz: {
|
|
parent: 'baz2',
|
|
},
|
|
baz2: {
|
|
parent: 'baz',
|
|
},
|
|
baz3: {
|
|
parent: 'bar',
|
|
},
|
|
},
|
|
});
|
|
done(
|
|
'Expected to throw error when alias has missing parent, got ' +
|
|
JSON.stringify(result)
|
|
);
|
|
} catch (err) {
|
|
//
|
|
}
|
|
|
|
// Fix it
|
|
expect(
|
|
validateIconSet(
|
|
{
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {
|
|
baz: {
|
|
parent: 'baz2',
|
|
},
|
|
baz2: {
|
|
parent: 'baz',
|
|
},
|
|
baz3: {
|
|
parent: 'bar',
|
|
},
|
|
},
|
|
},
|
|
{ fix: true }
|
|
)
|
|
).toEqual({
|
|
prefix: 'foo',
|
|
icons: {
|
|
bar: {
|
|
body: '<g />',
|
|
},
|
|
},
|
|
aliases: {
|
|
baz3: {
|
|
parent: 'bar',
|
|
},
|
|
},
|
|
});
|
|
|
|
done();
|
|
});
|
|
});
|