Skip to content

Commit 0ab5679

Browse files
committed
tests: address merge request comments
1 parent 623e9c8 commit 0ab5679

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

packages/scoped-custom-element-registry/test/Element.test.html.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
getTestElement,
55
getObservedAttributesTestElement,
66
getShadowRoot,
7-
getHTML
7+
getHTML,
88
} from './utils.js';
99

1010
describe('Element', () => {
@@ -112,38 +112,44 @@ describe('Element', () => {
112112

113113
describe('attributes', () => {
114114
it('should call setAttribute', () => {
115-
const {tagName, CustomElementClass} = getObservedAttributesTestElement(['foo']);
115+
const {tagName, CustomElementClass} = getObservedAttributesTestElement([
116+
'foo',
117+
]);
116118
customElements.define(tagName, CustomElementClass);
117-
const $el = getHTML('<div></div>');
118-
$el.innerHTML = `<${tagName}></${tagName}>`;
119+
const $el = document.createElement(tagName);
119120

120-
$el.firstElementChild.setAttribute('foo', 'bar');
121+
$el.setAttribute('foo', 'bar');
121122

122-
expect($el.firstElementChild.getAttribute('foo')).to.equal('bar');
123+
expect($el.getAttribute('foo')).to.equal('bar');
123124
});
125+
124126
it('should call removeAttribute', () => {
125-
const {tagName, CustomElementClass} = getObservedAttributesTestElement(['foo']);
127+
const {tagName, CustomElementClass} = getObservedAttributesTestElement([
128+
'foo',
129+
]);
126130
customElements.define(tagName, CustomElementClass);
127-
const $el = getHTML('<div></div>');
128-
$el.innerHTML = `<${tagName} foo></${tagName}>`;
131+
const $el = getHTML(`<${tagName} foo></${tagName}>`);
129132

130-
$el.firstElementChild.removeAttribute('foo');
133+
$el.removeAttribute('foo');
131134

132-
expect($el.firstElementChild.hasAttribute('foo')).to.be.false;
135+
expect($el.hasAttribute('foo')).to.be.false;
133136
});
137+
134138
it('should call toggleAttribute', () => {
135-
const {tagName, CustomElementClass} = getObservedAttributesTestElement(['foo']);
139+
const {tagName, CustomElementClass} = getObservedAttributesTestElement([
140+
'foo',
141+
]);
136142
customElements.define(tagName, CustomElementClass);
137-
const $el = getHTML('<div></div>');
138-
$el.innerHTML = `<${tagName}></${tagName}>`;
143+
const $el = document.createElement(tagName);
139144

140-
$el.firstElementChild.toggleAttribute('foo', false);
145+
$el.toggleAttribute('foo', false);
141146

142-
expect($el.firstElementChild.hasAttribute('foo')).to.be.false;
147+
expect($el.hasAttribute('foo')).to.be.false;
143148

144-
$el.firstElementChild.toggleAttribute('foo', true);
149+
$el.setAttribute('foo');
150+
$el.toggleAttribute('foo', true);
145151

146-
expect($el.firstElementChild.hasAttribute('foo')).to.be.true;
152+
expect($el.hasAttribute('foo')).to.be.true;
147153
});
148154
});
149155
});

packages/scoped-custom-element-registry/test/utils.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ export const getTestElement = () => ({
3131
});
3232

3333
/**
34-
*
35-
* @param {array<string>} observedAttributeNames the names of the attributes you want to observe
36-
* @returns {{Klass: typeof HTMLElement, tagName: string}}
34+
*
35+
* @param {Array<string>} observedAttributeNames the names of the attributes you want to observe
36+
* @returns {{CustomElementClass: typeof HTMLElement, tagName: string}}
3737
*/
38-
export const getObservedAttributesTestElement = (observedAttributeNames = []) => ({
38+
export const getObservedAttributesTestElement = (
39+
observedAttributeNames = []
40+
) => ({
3941
tagName: getTestTagName(),
4042
CustomElementClass: class extends HTMLElement {
4143
static get observedAttributes() {

0 commit comments

Comments
 (0)