mirror of
https://github.com/iconify/iconify.git
synced 2024-11-09 14:50:56 +00:00
Web component: test exports, reuse span when re-rendering
This commit is contained in:
parent
e80495fcd6
commit
07b3bf3819
@ -25,7 +25,7 @@
|
||||
"build:lib": "tsc -b",
|
||||
"build:dist": "rollup -c rollup.config.js",
|
||||
"test:jest": "jest --runInBand",
|
||||
"test:mjs": "echo \"TODO...\"",
|
||||
"test:mjs": "cross-env NODE_OPTIONS=--experimental-vm-modules node tests/import-test.mjs",
|
||||
"test": "npm run test:jest && npm run test:mjs"
|
||||
},
|
||||
"exports": {
|
||||
|
@ -28,7 +28,14 @@ export function renderIcon(parent: Element | ShadowRoot, state: RenderedState) {
|
||||
// Set element
|
||||
// Assumes first node is a style node created with updateStyle()
|
||||
if (parent.childNodes.length > 1) {
|
||||
parent.removeChild(parent.lastChild);
|
||||
const lastChild = parent.lastChild as HTMLElement;
|
||||
if (node.tagName === 'SPAN' && lastChild.tagName === node.tagName) {
|
||||
// Swap style instead of whole node
|
||||
lastChild.setAttribute('style', node.getAttribute('style'));
|
||||
} else {
|
||||
parent.replaceChild(node, lastChild);
|
||||
}
|
||||
} else {
|
||||
parent.appendChild(node);
|
||||
}
|
||||
parent.appendChild(node);
|
||||
}
|
||||
|
25
packages/icon/tests/import-test.mjs
Normal file
25
packages/icon/tests/import-test.mjs
Normal file
@ -0,0 +1,25 @@
|
||||
// Main file
|
||||
import { addIcon } from 'iconify-icon';
|
||||
|
||||
// Named import from .mjs
|
||||
import { loadIcons } from '../dist/iconify-icon.mjs';
|
||||
|
||||
/**
|
||||
* Simple assertion function
|
||||
*/
|
||||
function test(value, expected, message) {
|
||||
if (value !== expected) {
|
||||
console.error(
|
||||
'❌',
|
||||
message + `: expected ${value} to equal ${expected}`
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
console.log('✓', message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test named exports
|
||||
*/
|
||||
test(typeof addIcon, 'function', 'Testing addIcon named export');
|
||||
test(typeof loadIcons, 'function', 'Testing loadIcons named export');
|
Loading…
Reference in New Issue
Block a user