2
0
mirror of https://github.com/iconify/iconify.git synced 2024-12-13 14:13:06 +00:00
iconify/packages/browser-tests/tests/10-observer-creation-test.ts

45 lines
1.0 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';
2020-07-01 20:29:43 +00:00
import { setRoot } from '@iconify/iconify/lib/modules/root';
import {
initObserver,
isObserverPaused,
pauseObserver,
} from '@iconify/iconify/lib/modules/observer';
2020-04-28 09:47:35 +00:00
const expect = chai.expect;
describe('Testing observer creation', () => {
2020-06-11 21:46:47 +00:00
it('Creating observer and triggering event', (done) => {
2020-04-28 09:47:35 +00:00
const node = getNode('observer-creation');
2020-07-01 20:29:43 +00:00
setRoot(node);
2020-04-28 09:47:35 +00:00
let counter = 0;
node.innerHTML = '<div></div><ul><li>test</li><li>test2</li></ul>';
2020-07-01 20:29:43 +00:00
initObserver((root) => {
2020-04-28 09:47:35 +00:00
expect(root).to.be.equal(node);
counter++;
// Should be called only once
expect(counter).to.be.equal(1);
2020-07-01 20:29:43 +00:00
expect(isObserverPaused()).to.be.equal(false);
2020-04-28 09:47:35 +00:00
// Pause observer
2020-07-01 20:29:43 +00:00
pauseObserver();
expect(isObserverPaused()).to.be.equal(true);
2020-04-28 09:47:35 +00:00
done();
});
// Add few nodes to trigger observer
2020-07-01 20:29:43 +00:00
expect(isObserverPaused()).to.be.equal(false);
2020-04-28 09:47:35 +00:00
node.querySelector('div').innerHTML =
'<span class="test">Some text</span><i>!</i>';
});
});