import mocha from 'mocha'; import chai from 'chai'; import { getNode } from './node'; import Iconify from '@iconify/iconify/lib/iconify.without-api'; const expect = chai.expect; const selector = 'span.iconify, i.iconify, span.iconify-inline, i.iconify-inline'; const node1 = getNode('iconify-basic'); const node2 = getNode('iconify-basic'); // Do not observe document.body! Iconify.stopObserving(document.body); // Set root node Iconify.observe(node1); describe('Testing Iconify object (without API)', () => { const prefix = 'invalid-' + Date.now(); // Add mentioned icons to storage Iconify.addCollection({ prefix, icons: { 'account-box': { body: '', }, 'account-cash': { body: '', }, 'account': { body: '', }, 'home': { body: '', }, }, width: 24, height: 24, }); // Add one icon separately Iconify.addIcon(prefix + ':id-test', { body: '', width: 128, height: 128, }); it('Check iconExists', () => { expect(Iconify.iconExists(prefix + ':' + 'account')).to.be.equal(true); expect(Iconify.iconExists(prefix + ':' + 'missing')).to.be.equal(false); expect(Iconify.iconExists(prefix + '-123:' + 'missing')).to.be.equal( false ); }); it('Get SVG node', () => { const node = Iconify.renderSVG(prefix + ':account', { inline: true, }); expect(node).to.not.be.equal(null); const html = node.outerHTML; expect(html.indexOf(' { node1.innerHTML = '

Testing Iconify without API

' + ' ' + ' ' + ' ' + ' ' + ' ' + '
'; node2.innerHTML = '

This node should not be replaced

' + ''; // Icons should not have been replaced yet let list = node1.querySelectorAll(selector); expect(list.length).to.be.equal(5); list = node2.querySelectorAll(selector); expect(list.length).to.be.equal(1); // Check in ticks setTimeout(() => { setTimeout(() => { list = node1.querySelectorAll(selector); expect(list.length).to.be.equal(0); list = node2.querySelectorAll(selector); expect(list.length).to.be.equal(1); // Test SVG with ID const idTest = node1.querySelector('#ssvg-id-1st-place-medala'); expect(idTest).to.be.equal(null, 'Expecting ID to be replaced'); done(); }); }); }); });