2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-22 14:48:24 +00:00

Replace jest done function with promises in utils tests

This commit is contained in:
Vjacheslav Trushkin 2022-09-07 20:00:33 +03:00
parent 33b3e42834
commit 2dc12bd462
3 changed files with 679 additions and 608 deletions

View File

@ -46,7 +46,8 @@ describe('Testing validating alias', () => {
}); });
}); });
test('Null', (done) => { test('Null', () => {
return new Promise((fulfill, reject) => {
try { try {
validateIconSet({ validateIconSet({
prefix: 'foo', prefix: 'foo',
@ -57,8 +58,9 @@ describe('Testing validating alias', () => {
}, },
aliases: null, aliases: null,
}); });
done('Expected to throw error when aliases is null'); reject('Expected to throw error when aliases is null');
} catch (err) { return;
} catch {
// //
} }
@ -85,10 +87,12 @@ describe('Testing validating alias', () => {
}, },
}); });
done(); fulfill(true);
});
}); });
test('Invalid parent', (done) => { test('Invalid parent', () => {
return new Promise((fulfill, reject) => {
try { try {
const result = validateIconSet({ const result = validateIconSet({
prefix: 'foo', prefix: 'foo',
@ -103,11 +107,12 @@ describe('Testing validating alias', () => {
}, },
}, },
}); });
done( reject(
'Expected to throw error when alias has missing parent, got ' + 'Expected to throw error when alias has missing parent, got ' +
JSON.stringify(result) JSON.stringify(result)
); );
} catch (err) { return;
} catch {
// //
} }
@ -138,10 +143,12 @@ describe('Testing validating alias', () => {
}, },
}); });
done(); fulfill(true);
});
}); });
test('Invalid parent, 2 levels', (done) => { test('Invalid parent, 2 levels', () => {
return new Promise((fulfill, reject) => {
try { try {
const result = validateIconSet({ const result = validateIconSet({
prefix: 'foo', prefix: 'foo',
@ -159,11 +166,12 @@ describe('Testing validating alias', () => {
}, },
}, },
}); });
done( reject(
'Expected to throw error when alias has missing parent, got ' + 'Expected to throw error when alias has missing parent, got ' +
JSON.stringify(result) JSON.stringify(result)
); );
} catch (err) { return;
} catch {
// //
} }
@ -197,10 +205,12 @@ describe('Testing validating alias', () => {
}, },
}); });
done(); fulfill(true);
});
}); });
test('Invalid parent, 2 levels, reverse order', (done) => { test('Invalid parent, 2 levels, reverse order', () => {
return new Promise((fulfill, reject) => {
try { try {
const result = validateIconSet({ const result = validateIconSet({
prefix: 'foo', prefix: 'foo',
@ -218,11 +228,12 @@ describe('Testing validating alias', () => {
}, },
}, },
}); });
done( reject(
'Expected to throw error when alias has missing parent, got ' + 'Expected to throw error when alias has missing parent, got ' +
JSON.stringify(result) JSON.stringify(result)
); );
} catch (err) { return;
} catch {
// //
} }
@ -256,10 +267,12 @@ describe('Testing validating alias', () => {
}, },
}); });
done(); fulfill(true);
});
}); });
test('Parent loop', (done) => { test('Parent loop', () => {
return new Promise((fulfill, reject) => {
try { try {
const result = validateIconSet({ const result = validateIconSet({
prefix: 'foo', prefix: 'foo',
@ -280,11 +293,12 @@ describe('Testing validating alias', () => {
}, },
}, },
}); });
done( reject(
'Expected to throw error when alias has missing parent, got ' + 'Expected to throw error when alias has missing parent, got ' +
JSON.stringify(result) JSON.stringify(result)
); );
} catch (err) { return;
} catch {
// //
} }
@ -326,6 +340,7 @@ describe('Testing validating alias', () => {
}, },
}); });
done(); fulfill(true);
});
}); });
}); });

View File

@ -54,7 +54,8 @@ describe('Testing validating icon', () => {
}); });
// Required string // Required string
test('body', (done) => { test('body', () => {
return new Promise((fulfill, reject) => {
// Missing body // Missing body
try { try {
validateIconSet({ validateIconSet({
@ -65,8 +66,9 @@ describe('Testing validating icon', () => {
}, },
}, },
}); });
done('Expected to throw error when body is missing'); reject('Expected to throw error when body is missing');
} catch (err) { return;
} catch {
// //
} }
@ -84,10 +86,11 @@ describe('Testing validating icon', () => {
fix: true, fix: true,
} }
); );
done( reject(
'Expected to throw error when body is missing and cannot be fixed' 'Expected to throw error when body is missing and cannot be fixed'
); );
} catch (err) { return;
} catch {
// //
} }
@ -117,11 +120,11 @@ describe('Testing validating icon', () => {
}, },
}, },
}); });
} catch (err) { } catch {
done( reject(
'Expected to not throw error when body is missing, but icon set can be fixed' 'Expected to not throw error when body is missing, but icon set can be fixed'
); );
// return;
} }
validationValues.forEach((item, value) => { validationValues.forEach((item, value) => {
@ -137,11 +140,15 @@ describe('Testing validating icon', () => {
}); });
if (item.type !== 'string') { if (item.type !== 'string') {
done(`Expected to throw error when body is ${item.text}`); reject(
`Expected to throw error when body is ${item.text}`
);
return;
} }
} catch (err) { } catch {
if (item.type === 'string') { if (item.type === 'string') {
done(`Expected to pass when body is ${item.text}`); reject(`Expected to pass when body is ${item.text}`);
return;
} }
} }
@ -162,11 +169,15 @@ describe('Testing validating icon', () => {
); );
if (item.type !== 'string') { if (item.type !== 'string') {
done(`Expected to throw error when body is ${item.text}`); reject(
`Expected to throw error when body is ${item.text}`
);
return;
} }
} catch (err) { } catch {
if (item.type === 'string') { if (item.type === 'string') {
done(`Expected to pass when body is ${item.text}`); reject(`Expected to pass when body is ${item.text}`);
return;
} }
} }
@ -188,17 +199,20 @@ describe('Testing validating icon', () => {
fix: true, fix: true,
} }
); );
} catch (err) { } catch {
done('Expected to pass when another icon is valid'); reject('Expected to pass when another icon is valid');
return;
} }
}); });
done(); fulfill(true);
});
}); });
// Numbers // Numbers
['width', 'height', 'left', 'top', 'rotate'].forEach((prop) => { ['width', 'height', 'left', 'top', 'rotate'].forEach((prop) => {
test(prop, (done) => { test(prop, () => {
return new Promise((fulfill, reject) => {
// Validate without fixing // Validate without fixing
validationValues.forEach((item, value) => { validationValues.forEach((item, value) => {
try { try {
@ -213,13 +227,17 @@ describe('Testing validating icon', () => {
}); });
if (item.type !== 'number') { if (item.type !== 'number') {
done( reject(
`Expected to throw error when ${prop} is ${item.text}` `Expected to throw error when ${prop} is ${item.text}`
); );
return;
} }
} catch (err) { } catch {
if (item.type === 'number') { if (item.type === 'number') {
done(`Expected to pass when ${prop} is ${item.text}`); reject(
`Expected to pass when ${prop} is ${item.text}`
);
return;
} }
} }
}); });
@ -259,20 +277,23 @@ describe('Testing validating icon', () => {
bar: icon, bar: icon,
}, },
}); });
} catch (err) { } catch {
done( reject(
`Expected to not throw error when ${prop} is being fixed` `Expected to not throw error when ${prop} is being fixed`
); );
return;
} }
}); });
done(); fulfill(true);
});
}); });
}); });
// Boolean // Boolean
['hFlip', 'vFlip', 'hidden'].forEach((prop) => { ['hFlip', 'vFlip', 'hidden'].forEach((prop) => {
test(prop, (done) => { test(prop, () => {
return new Promise((fulfill, reject) => {
validationValues.forEach((item, value) => { validationValues.forEach((item, value) => {
// Validate // Validate
try { try {
@ -287,13 +308,17 @@ describe('Testing validating icon', () => {
}); });
if (item.type !== 'boolean') { if (item.type !== 'boolean') {
done( reject(
`Expected to throw error when ${prop} is ${item.text}` `Expected to throw error when ${prop} is ${item.text}`
); );
return;
} }
} catch (err) { } catch {
if (item.type === 'boolean') { if (item.type === 'boolean') {
done(`Expected to pass when ${prop} is ${item.text}`); reject(
`Expected to pass when ${prop} is ${item.text}`
);
return;
} }
} }
}); });
@ -333,19 +358,22 @@ describe('Testing validating icon', () => {
bar: icon, bar: icon,
}, },
}); });
} catch (err) { } catch {
done( reject(
`Expected to not throw error when ${prop} is being fixed` `Expected to not throw error when ${prop} is being fixed`
); );
return;
} }
}); });
done(); fulfill(true);
});
}); });
}); });
// Unexpected field // Unexpected field
test('foo', (done) => { test('foo', () => {
return new Promise((fulfill, reject) => {
validationValues.forEach((item, value) => { validationValues.forEach((item, value) => {
// Validate // Validate
try { try {
@ -360,11 +388,15 @@ describe('Testing validating icon', () => {
}); });
if (item.type === 'object') { if (item.type === 'object') {
done(`Expected to throw error when value is ${item.text}`); reject(
`Expected to throw error when value is ${item.text}`
);
return;
} }
} catch (err) { } catch {
if (item.type !== 'object') { if (item.type !== 'object') {
done(`Expected to pass when value is ${item.text}`); reject(`Expected to pass when value is ${item.text}`);
return;
} }
} }
}); });
@ -404,11 +436,15 @@ describe('Testing validating icon', () => {
bar: icon, bar: icon,
}, },
}); });
} catch (err) { } catch {
done(`Expected to not throw error when value is being fixed`); reject(
`Expected to not throw error when value is being fixed`
);
return;
} }
}); });
done(); fulfill(true);
});
}); });
}); });

View File

@ -1,36 +1,42 @@
import { validateIconSet } from '../lib/icon-set/validate'; import { validateIconSet } from '../lib/icon-set/validate';
describe('Testing validation', () => { describe('Testing validation', () => {
test('Not object', (done) => { test('Not object', () => {
return new Promise((fulfill, reject) => {
try { try {
validateIconSet(void 0); validateIconSet(void 0);
done('Expected to throw error on undefined'); reject('Expected to throw error on undefined');
} catch (err) { return;
} catch {
// //
} }
try { try {
validateIconSet({}); validateIconSet({});
done('Expected to throw error on empty object'); reject('Expected to throw error on empty object');
} catch (err) { return;
} catch {
// //
} }
try { try {
validateIconSet(null); validateIconSet(null);
done('Expected to throw error on null'); reject('Expected to throw error on null');
} catch (err) { return;
} catch {
// //
} }
try { try {
validateIconSet([]); validateIconSet([]);
done('Expected to throw error on array'); reject('Expected to throw error on array');
} catch (err) { return;
} catch {
// //
} }
done(); fulfill(true);
});
}); });
test('Valid set', () => { test('Valid set', () => {
@ -53,13 +59,15 @@ describe('Testing validation', () => {
}); });
}); });
test('Missing stuff', (done) => { test('Missing stuff', () => {
return new Promise((fulfill, reject) => {
try { try {
validateIconSet({ validateIconSet({
prefix: 'foo', prefix: 'foo',
}); });
done('Expected to throw error when icons are missing'); reject('Expected to throw error when icons are missing');
} catch (err) { return;
} catch {
// //
} }
@ -68,22 +76,26 @@ describe('Testing validation', () => {
prefix: 'foo', prefix: 'foo',
icons: {}, icons: {},
}); });
done('Expected to throw error when icons are empty'); reject('Expected to throw error when icons are empty');
} catch (err) { return;
} catch {
// //
} }
try { try {
validateIconSet([]); validateIconSet([]);
done('Expected to throw error on array'); reject('Expected to throw error on array');
} catch (err) { return;
} catch {
// //
} }
done(); fulfill(true);
});
}); });
test('Characters', (done) => { test('Characters', () => {
return new Promise((fulfill, reject) => {
// Correct icon set // Correct icon set
expect( expect(
validateIconSet({ validateIconSet({
@ -136,10 +148,11 @@ describe('Testing validation', () => {
e01: 'baz', e01: 'baz',
}, },
}); });
done( reject(
'Expected to throw error when character points to missing icon' 'Expected to throw error when character points to missing icon'
); );
} catch (err) { return;
} catch {
// //
} }
@ -180,8 +193,9 @@ describe('Testing validation', () => {
test: 'bar', test: 'bar',
}, },
}); });
done('Expected to throw error when character is invalid'); reject('Expected to throw error when character is invalid');
} catch (err) { return;
} catch {
// //
} }
@ -216,10 +230,12 @@ describe('Testing validation', () => {
}, },
}); });
done(); fulfill(true);
});
}); });
test('Invalid default values', (done) => { test('Invalid default values', () => {
return new Promise((fulfill, reject) => {
try { try {
validateIconSet( validateIconSet(
{ {
@ -237,8 +253,9 @@ describe('Testing validation', () => {
}, },
{ fix: true } { fix: true }
); );
done('Expected to throw error for bad default properties'); reject('Expected to throw error for bad default properties');
} catch (err) { return;
} catch {
// //
} }
@ -257,8 +274,9 @@ describe('Testing validation', () => {
}, },
{ fix: true } { fix: true }
); );
done('Expected to throw error for bad default properties'); reject('Expected to throw error for bad default properties');
} catch (err) { return;
} catch {
// //
} }
@ -277,11 +295,13 @@ describe('Testing validation', () => {
}, },
{ fix: true } { fix: true }
); );
done('Expected to throw error for bad default properties'); reject('Expected to throw error for bad default properties');
} catch (err) { return;
} catch {
// //
} }
done(); fulfill(true);
});
}); });
}); });