2
0
mirror of https://github.com/iconify/iconify.git synced 2024-10-23 17:12:03 +00:00
iconify/components/svelte/tests/api/10-api-mock.test.ts

47 lines
991 B
TypeScript
Raw Normal View History

/**
* @jest-environment jsdom
*/
import { loadIcons, iconExists } from '../../dist';
2021-05-01 20:38:56 +00:00
import { mockAPIData } from '@iconify/core/lib/api/modules/mock';
import { provider, nextPrefix } from './load';
describe('Testing fake API', () => {
2022-12-25 22:32:45 +00:00
test('using fake API to load icon', () => {
return new Promise((fulfill, reject) => {
const prefix = nextPrefix();
const name = 'mock-test';
const iconName = `@${provider}:${prefix}:${name}`;
mockAPIData({
type: 'icons',
provider,
2021-05-01 20:38:56 +00:00
prefix,
2022-12-25 22:32:45 +00:00
response: {
prefix,
icons: {
[name]: {
body: '<g />',
},
2021-05-01 20:38:56 +00:00
},
},
2022-12-25 22:32:45 +00:00
});
2021-05-01 20:38:56 +00:00
2022-12-25 22:32:45 +00:00
// Check if icon has been loaded
expect(iconExists(iconName)).toBe(false);
2021-05-01 20:38:56 +00:00
2022-12-25 22:32:45 +00:00
// Load icon
loadIcons([iconName], (loaded, missing, pending) => {
expect(loaded).toMatchObject([
{
provider,
prefix,
name,
},
]);
expect(missing).toMatchObject([]);
expect(pending).toMatchObject([]);
fulfill(true);
});
2021-05-01 20:38:56 +00:00
});
});
});