From 9cf168ee18e441900e7ea296babf8d13475507b7 Mon Sep 17 00:00:00 2001 From: valdrinkoshi Date: Fri, 5 Aug 2016 14:16:04 -0700 Subject: [PATCH] restructure tests --- test/index.js | 90 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/test/index.js b/test/index.js index e25facd..f4552ed 100644 --- a/test/index.js +++ b/test/index.js @@ -122,67 +122,97 @@ describe('Basic', function() { }); }); + describe('ShadowDOM v0', function() { + if (!Element.prototype.createShadowRoot) { + console.log('ShadowDOM v0 is not supported by the browser.'); + return; + } + let fixture, host; - if (!document.createElement('div').createShadowRoot) { - console.log('ShadowDOM v0 is not supported by the browser.'); - } else { - it('should apply inside shadow trees', function() { - const fixture = document.querySelector('#fixture'); + beforeEach(function() { + fixture = document.querySelector('#fixture'); fixture.inert = false; - const host = document.createElement('div'); + host = document.createElement('div'); fixture.appendChild(host); - const shadowRoot = host.createShadowRoot(); + host.createShadowRoot(); + }); + + afterEach(function() { + fixture.removeChild(host); + }); + + it('should apply inside shadow trees', function() { const shadowButton = document.createElement('button'); shadowButton.textContent = 'Shadow button'; - shadowRoot.appendChild(shadowButton); + host.shadowRoot.appendChild(shadowButton); fixture.inert = true; expect(isUnfocusable(shadowButton)).to.equal(true); }); it('should apply inert styles inside shadow trees', function() { - const fixture = document.querySelector('#fixture'); - const host = document.createElement('div'); - fixture.appendChild(host); - const shadowRoot = host.createShadowRoot(); const shadowButton = document.createElement('button'); shadowButton.textContent = 'Shadow button'; - shadowRoot.appendChild(shadowButton); + host.shadowRoot.appendChild(shadowButton); shadowButton.inert = true; expect(getComputedStyle(shadowButton).pointerEvents).to.equal('none'); }); - it('should apply inside shadow trees distributed content (ShadowDOM v0)', function() { - const fixture = document.querySelector('#fixture'); - fixture.inert = false; - const host = document.createElement('div'); - fixture.appendChild(host); - const shadowRoot = host.createShadowRoot(); - shadowRoot.appendChild(document.createElement('content')); + it('should apply inside shadow trees distributed content', function() { + host.shadowRoot.appendChild(document.createElement('content')); const distributedButton = document.createElement('button'); distributedButton.textContent = 'Distributed button'; host.appendChild(distributedButton); fixture.inert = true; expect(isUnfocusable(distributedButton)).to.equal(true); }); - } + }); + + describe('ShadowDOM v1', function() { + if (!Element.prototype.attachShadow) { + console.log('ShadowDOM v1 is not supported by the browser.'); + return; + } + let fixture, host; - if (!document.createElement('div').attachShadow) { - console.log('ShadowDOM v1 is not supported by the browser.'); - } else { - it('should apply inside shadow trees distributed content (ShadowDOM v1)', function() { - const fixture = document.querySelector('#fixture'); + beforeEach(function() { + fixture = document.querySelector('#fixture'); fixture.inert = false; - const host = document.createElement('div'); + host = document.createElement('div'); fixture.appendChild(host); - const shadowRoot = host.attachShadow({mode: 'open'}); - shadowRoot.appendChild(document.createElement('slot')); + host.attachShadow({ + mode: 'open' + }); + }); + + afterEach(function() { + fixture.removeChild(host); + }); + + it('should apply inside shadow trees', function() { + const shadowButton = document.createElement('button'); + shadowButton.textContent = 'Shadow button'; + host.shadowRoot.appendChild(shadowButton); + fixture.inert = true; + expect(isUnfocusable(shadowButton)).to.equal(true); + }); + + it('should apply inert styles inside shadow trees', function() { + const shadowButton = document.createElement('button'); + shadowButton.textContent = 'Shadow button'; + host.shadowRoot.appendChild(shadowButton); + shadowButton.inert = true; + expect(getComputedStyle(shadowButton).pointerEvents).to.equal('none'); + }); + + it('should apply inside shadow trees distributed content', function() { + host.shadowRoot.appendChild(document.createElement('slot')); const distributedButton = document.createElement('button'); distributedButton.textContent = 'Distributed button'; host.appendChild(distributedButton); fixture.inert = true; expect(isUnfocusable(distributedButton)).to.equal(true); }); - } + }); }); describe('nested inert regions', function() {