Skip to content
Snippets Groups Projects
Select Git revision
  • 799ec363689ee2f13c7e9e27fac8e7c29969602d
  • master default protected
  • 1.31
  • 4.38.8
  • 4.38.7
  • 4.38.6
  • 4.38.5
  • 4.38.4
  • 4.38.3
  • 4.38.2
  • 4.38.1
  • 4.38.0
  • 4.37.2
  • 4.37.1
  • 4.37.0
  • 4.36.0
  • 4.35.0
  • 4.34.1
  • 4.34.0
  • 4.33.1
  • 4.33.0
  • 4.32.2
  • 4.32.1
23 results

link.mjs

Blame
  • Volker Schukai's avatar
    799ec363
    History
    link.mjs 2.47 KiB
    'use strict';
    
    import chai from "chai"
    import {Link} from "../../../../source/dom/resource/link.mjs";
    import {DataUrl} from "../../../../source/types/dataurl.mjs";
    import {ID} from "../../../../source/types/id.mjs";
    import {chaiDom} from "../../../util/chai-dom.mjs";
    import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../../util/cleanupdom.mjs";
    import {initJSDOM} from "../../../util/jsdom.mjs";
    
    let expect = chai.expect;
    
    chai.use(chaiDom);
    
    
    
    describe('Link', function () {
    
        before(function (done) {
            initJSDOM().then(() => {
                done()
            });
        });
    
        beforeEach(() => {
            initMutationObserverForTesting()
        })
    
        afterEach(() => {
            cleanupDOMFromTesting();
        })
    
        describe('Link()', function () {
            this.timeout(5000);
    
            it('connect().available()', function (done) {
    
                const link = new Link({
                    href: new DataUrl('', 'text/css').toString(),
                    rel: 'stylesheet'
                });
    
                link.connect().available().then(() => {
                    done()
                }).catch(e => done(e));
    
            })
        });
    
        describe('External Link', () => {
            this.timeout(5000);
    
            let id = new ID('link').toString();
            let link, url = 'https://monsterjs.org/assets/empty.css?' + id;
    
            beforeEach(() => {
    
                link = new Link({
                    href: url,
                    id: id,
                    rel: 'stylesheet'
                });
    
            });
    
            it('append and remove Link ', (done) => {
    
                expect(link.isConnected()).to.be.false;
    
                link.connect().available().then(() => {
                    expect(link.isConnected()).to.be.true;
                    expect(document.querySelector('[href="' + url + '"]')).to.exist;
    
                    document.getElementById(id).remove();
                    expect(link.isConnected()).to.be.false;
                    expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
    
                    link.connect().available().then(() => {
                        expect(link.isConnected()).to.be.true;
                        expect(document.querySelector('[href="' + url + '"]')).to.exist;
    
                        document.getElementById(id).remove();
                        expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
                        expect(link.isConnected()).to.be.false;
    
                        done()
                    }).catch(e => done(e));
    
    
                }).catch(e => done(e));
    
    
            });
    
    
        });
    
    
    });