1
0
mirror of https://github.com/svg/svgo.git synced 2026-01-25 18:41:39 +03:00
Files
svgo/test/plugins/addClassesToSVGElement.test.js
Seth Falco 53aad59dc9 feat(addClassesToSVGElement): allow function as param (#1966)
Updates the interface for addClassesToSVGElement to match prefixIds,
where we'll accept Array<string|function> instead of just a string.
2024-03-01 00:50:30 +00:00

37 lines
903 B
JavaScript

import { optimize } from '../../lib/svgo.js';
test('should accept function as className parameter', () => {
const svg = `<svg xmlns="http://www.w3.org/2000/svg"/>`;
expect(
optimize(svg, {
path: 'uwu.svg',
plugins: [
{
name: 'addClassesToSVGElement',
params: {
classNames: [
'icon',
(_, info) => `icon__${info?.path?.split('.')[0]}`,
],
},
},
],
}).data,
).toBe(`<svg xmlns="http://www.w3.org/2000/svg" class="icon icon__uwu"/>`);
expect(
optimize(svg, {
path: 'uwu.svg',
plugins: [
{
name: 'addClassesToSVGElement',
params: {
className: (_, info) => `icon__${info?.path?.split('.')[0]}`,
},
},
],
}).data,
).toBe(`<svg xmlns="http://www.w3.org/2000/svg" class="icon__uwu"/>`);
});