2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-14 14:38:25 +00:00
iconify/demo/browser-tests/tests/30-iconify-api-test.ts

53 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-04-28 09:47:35 +00:00
import mocha from 'mocha';
import chai from 'chai';
import { getNode } from './node';
import Iconify from '@iconify/iconify/lib/iconify';
const expect = chai.expect;
const selector =
'span.iconify, i.iconify, span.iconify-inline, i.iconify-inline';
// Do not observe document.body!
Iconify.stopObserving(document.documentElement);
2020-04-28 09:47:35 +00:00
// Create node to observe
const observedNode = getNode('iconify-api');
const ignoredNode = getNode('iconify-api');
Iconify.observe(observedNode);
observedNode.innerHTML =
2020-12-16 09:48:50 +00:00
'<div><p>Testing Iconify with API (should render SVG!)</p><ul>' +
2020-04-28 09:47:35 +00:00
'<li>Inline icons:' +
' <span class="iconify-inline" data-icon="mdi:home" style="color: red; box-shadow: 0 0 2px black;"></span>' +
' <i class="iconify iconify-inline test-icon iconify--mdi-account" data-icon="mdi:account" style="vertical-align: 0;" data-flip="horizontal" aria-hidden="false"></i>' +
'</li>' +
'<li>Block icons:' +
' <i class="iconify" data-icon="mdi:account-cash" title="&lt;Cash&gt;!"></i>' +
' <span class="iconify" data-icon="mdi:account-box" data-inline="true" data-rotate="2" data-width="42"></span>' +
'</li>' +
'</ul></div>';
ignoredNode.innerHTML =
'<div>This node should not have icons! <span class="iconify-inline" data-icon="mdi:home" style="color: red; box-shadow: 0 0 2px black;"></span>';
describe('Testing Iconify object with API', () => {
2020-04-28 09:47:35 +00:00
it('Rendering icons with API', () => {
// Icons should have been replaced by now
let list = observedNode.querySelectorAll(selector);
2020-04-28 09:47:35 +00:00
expect(list.length).to.be.equal(0);
list = observedNode.querySelectorAll('svg.iconify');
2020-04-28 09:47:35 +00:00
expect(list.length).to.be.equal(4);
// Icons in ignored node should not have been replaced
list = ignoredNode.querySelectorAll(selector);
expect(list.length).to.be.equal(1);
list = ignoredNode.querySelectorAll('svg.iconify');
expect(list.length).to.be.equal(0);
2020-04-28 09:47:35 +00:00
});
});