import mocha from 'mocha'; import chai from 'chai'; import { getNode } from './node'; import { addFinder } from '@iconify/iconify/lib/modules/finder'; import { finder as iconifyFinder } from '@iconify/iconify/lib/finders/iconify'; import { finder as iconifyIconFinder } from '@iconify/iconify/lib/finders/iconify-icon'; import { getStorage, addIconSet } from '@iconify/core/lib/storage'; import { setRoot } from '@iconify/iconify/lib/modules/root'; import { scanDOM } from '@iconify/iconify/lib/modules/scanner'; const expect = chai.expect; // Add finders addFinder(iconifyFinder); addFinder(iconifyIconFinder); describe('Scanning DOM', () => { // Add mentioned icons to storage const storage = getStorage('', 'mdi'); addIconSet(storage, { prefix: 'mdi', icons: { 'account-box': { body: '', }, 'account-cash': { body: '', }, 'account': { body: '', }, 'home': { body: '', }, }, width: 24, height: 24, }); it('Scan DOM with preloaded icons', () => { const node = getNode('scan-dom'); node.innerHTML = '

Testing scanning DOM

    ' + '
  • Valid icons:' + ' ' + ' ' + '
  • ' + '
  • Block icon:' + ' ' + ' ' + '
  • ' + '
'; setRoot(node); scanDOM(); // Find elements const elements = node.querySelectorAll('svg.iconify'); expect(elements.length).to.be.equal(4); }); it('Scan DOM with unattached root', () => { const node = document.createElement('div'); node.innerHTML = ''; scanDOM(node); // Find elements const elements = node.querySelectorAll('svg.iconify'); expect(elements.length).to.be.equal(1); }); it('Scan DOM with icon as root', () => { const node = document.createElement('span'); node.setAttribute('data-icon', 'mdi:home'); scanDOM(node); // Check node expect(node.tagName).to.be.equal('SPAN'); expect(node.innerHTML).to.be.equal(''); }); });