2
0
mirror of https://github.com/iconify/iconify.git synced 2024-09-29 13:39:08 +00:00
iconify/components/svelte/tests/offline/20-attributes.test.ts

86 lines
2.0 KiB
TypeScript
Raw Normal View History

import { describe, test, expect } from 'vitest';
2021-04-30 09:51:31 +00:00
import { render } from '@testing-library/svelte';
import Icon from '../../offline';
2021-04-30 09:51:31 +00:00
const iconData = {
body: '<path d="M4 19h16v2H4zm5-4h11v2H9zm-5-4h16v2H4zm0-8h16v2H4zm5 4h11v2H9z" fill="currentColor"/>',
2021-04-30 09:51:31 +00:00
width: 24,
height: 24,
};
describe('Padding attributes', () => {
test('title', () => {
const renderResult = render(Icon, {
icon: iconData,
// @ts-expect-error
title: 'Icon!',
});
expect(renderResult.container.innerHTML).toContain('title="Icon!"');
2021-04-30 09:51:31 +00:00
});
test('aria-hidden', () => {
// dashes, string value
const renderResult = render(Icon, {
2021-04-30 09:51:31 +00:00
'icon': iconData,
'aria-hidden': 'false',
});
expect(renderResult.container.innerHTML).not.toContain('aria-hidden');
2021-04-30 09:51:31 +00:00
});
test('ariaHidden', () => {
// camelCase, boolean value
const renderResult = render(Icon, {
2021-04-30 09:51:31 +00:00
icon: iconData,
// @ts-expect-error
2021-04-30 09:51:31 +00:00
ariaHidden: false,
});
expect(renderResult.container.innerHTML).not.toContain('aria-hidden');
2021-04-30 09:51:31 +00:00
});
test('style', () => {
const renderResult = render(Icon, {
2021-04-30 09:51:31 +00:00
icon: iconData,
style: 'vertical-align: 0; color: red;',
});
expect(renderResult.container.innerHTML).toContain(
'style="vertical-align: 0; color: red;"'
);
2021-04-30 09:51:31 +00:00
});
test('color', () => {
const renderResult = render(Icon, {
2021-04-30 09:51:31 +00:00
icon: iconData,
color: 'red',
});
expect(renderResult.container.innerHTML).toContain(
'style="color: red;"'
);
2021-04-30 09:51:31 +00:00
});
test('color with style', () => {
const renderResult = render(Icon, {
2021-04-30 09:51:31 +00:00
icon: iconData,
color: 'red',
style: 'color: green;',
});
// In Svelte component, `color` overrides `style`
expect(renderResult.container.innerHTML).toContain(
'style="color: red;"'
);
expect(renderResult.container.innerHTML).not.toContain('green');
2021-04-30 09:51:31 +00:00
});
test('attributes that cannot change', () => {
const renderResult = render(Icon, {
2021-04-30 09:51:31 +00:00
icon: iconData,
viewBox: '0 0 0 0',
});
expect(renderResult.container.innerHTML).toContain(
'viewBox="0 0 24 24"'
);
expect(renderResult.container.innerHTML).not.toContain('0 0 0 0');
2021-04-30 09:51:31 +00:00
});
});