2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-14 22:46:06 +00:00
iconify/iconify-icon/icon/tests/mock-api-test.ts

42 lines
917 B
TypeScript
Raw Normal View History

import { iconLoaded } from '@iconify/core/lib/storage/functions';
2022-04-29 20:19:22 +00:00
import { loadIcon } from '@iconify/core/lib/api/icons';
2022-06-19 14:47:45 +00:00
import { defaultIconProps } from '@iconify/utils/lib/icon/defaults';
import { fakeAPI, nextPrefix, mockAPIData } from '../src/tests/helpers';
2022-04-29 20:19:22 +00:00
describe('Testing mock API', () => {
it('Setting up API', async () => {
// Set config
const provider = nextPrefix();
const prefix = nextPrefix();
fakeAPI(provider);
// Mock data
const name = 'mock-test';
const iconName = `@${provider}:${prefix}:${name}`;
mockAPIData({
type: 'icons',
provider,
prefix,
response: {
prefix,
icons: {
[name]: {
body: '<g />',
},
},
},
});
// Check if icon has been loaded
expect(iconLoaded(iconName)).toBe(false);
2022-04-29 20:19:22 +00:00
// Load icon
const data = await loadIcon(iconName);
expect(data).toEqual({
2022-06-19 14:47:45 +00:00
...defaultIconProps,
2022-04-29 20:19:22 +00:00
body: '<g />',
});
});
});