|
4 | 4 | getTestElement,
|
5 | 5 | getObservedAttributesTestElement,
|
6 | 6 | getShadowRoot,
|
7 |
| - getHTML |
| 7 | + getHTML, |
8 | 8 | } from './utils.js';
|
9 | 9 |
|
10 | 10 | describe('Element', () => {
|
@@ -112,38 +112,44 @@ describe('Element', () => {
|
112 | 112 |
|
113 | 113 | describe('attributes', () => {
|
114 | 114 | it('should call setAttribute', () => {
|
115 |
| - const {tagName, CustomElementClass} = getObservedAttributesTestElement(['foo']); |
| 115 | + const {tagName, CustomElementClass} = getObservedAttributesTestElement([ |
| 116 | + 'foo', |
| 117 | + ]); |
116 | 118 | customElements.define(tagName, CustomElementClass);
|
117 |
| - const $el = getHTML('<div></div>'); |
118 |
| - $el.innerHTML = `<${tagName}></${tagName}>`; |
| 119 | + const $el = document.createElement(tagName); |
119 | 120 |
|
120 |
| - $el.firstElementChild.setAttribute('foo', 'bar'); |
| 121 | + $el.setAttribute('foo', 'bar'); |
121 | 122 |
|
122 |
| - expect($el.firstElementChild.getAttribute('foo')).to.equal('bar'); |
| 123 | + expect($el.getAttribute('foo')).to.equal('bar'); |
123 | 124 | });
|
| 125 | + |
124 | 126 | it('should call removeAttribute', () => {
|
125 |
| - const {tagName, CustomElementClass} = getObservedAttributesTestElement(['foo']); |
| 127 | + const {tagName, CustomElementClass} = getObservedAttributesTestElement([ |
| 128 | + 'foo', |
| 129 | + ]); |
126 | 130 | customElements.define(tagName, CustomElementClass);
|
127 |
| - const $el = getHTML('<div></div>'); |
128 |
| - $el.innerHTML = `<${tagName} foo></${tagName}>`; |
| 131 | + const $el = getHTML(`<${tagName} foo></${tagName}>`); |
129 | 132 |
|
130 |
| - $el.firstElementChild.removeAttribute('foo'); |
| 133 | + $el.removeAttribute('foo'); |
131 | 134 |
|
132 |
| - expect($el.firstElementChild.hasAttribute('foo')).to.be.false; |
| 135 | + expect($el.hasAttribute('foo')).to.be.false; |
133 | 136 | });
|
| 137 | + |
134 | 138 | it('should call toggleAttribute', () => {
|
135 |
| - const {tagName, CustomElementClass} = getObservedAttributesTestElement(['foo']); |
| 139 | + const {tagName, CustomElementClass} = getObservedAttributesTestElement([ |
| 140 | + 'foo', |
| 141 | + ]); |
136 | 142 | customElements.define(tagName, CustomElementClass);
|
137 |
| - const $el = getHTML('<div></div>'); |
138 |
| - $el.innerHTML = `<${tagName}></${tagName}>`; |
| 143 | + const $el = document.createElement(tagName); |
139 | 144 |
|
140 |
| - $el.firstElementChild.toggleAttribute('foo', false); |
| 145 | + $el.toggleAttribute('foo', false); |
141 | 146 |
|
142 |
| - expect($el.firstElementChild.hasAttribute('foo')).to.be.false; |
| 147 | + expect($el.hasAttribute('foo')).to.be.false; |
143 | 148 |
|
144 |
| - $el.firstElementChild.toggleAttribute('foo', true); |
| 149 | + $el.setAttribute('foo'); |
| 150 | + $el.toggleAttribute('foo', true); |
145 | 151 |
|
146 |
| - expect($el.firstElementChild.hasAttribute('foo')).to.be.true; |
| 152 | + expect($el.hasAttribute('foo')).to.be.true; |
147 | 153 | });
|
148 | 154 | });
|
149 | 155 | });
|
0 commit comments