Skip to content

Commit b6d2452

Browse files
committed
chore: update in response to review comments
1 parent 0b3148a commit b6d2452

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

packages/@lwc/integration-not-karma/helpers/setup.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ hijackGlobal('afterEach', (afterEach) => {
6565
// Ensure the DOM is in a clean state
6666
document.body.replaceChildren();
6767
document.head.replaceChildren();
68+
window.__lwcResetGlobalStylesheets();
6869
});
6970
});
7071

packages/@lwc/integration-not-karma/test/component/LightningElement.attachInternals/elementInternals/formAssociated/index.spec.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,27 @@ import FormAssociatedNoAttachInternals from 'x/formAssociatedNoAttachInternals';
88
import FormAssociatedFalseNoAttachInternals from 'x/formAssociatedFalseNoAttachInternals';
99
import { ENABLE_ELEMENT_INTERNALS_AND_FACE } from '../../../../../helpers/constants.js';
1010

11+
const formAssociatedFalsyTest = (tagName, ctor) => {
12+
const form = document.createElement('form');
13+
document.body.appendChild(form);
14+
15+
const elm = createElement(`x-${tagName}`, { is: ctor });
16+
form.appendChild(elm);
17+
18+
const { internals } = elm;
19+
expect(() => internals.form).toThrow();
20+
expect(() => internals.setFormValue('2019-03-15')).toThrow();
21+
expect(() => internals.willValidate).toThrow();
22+
expect(() => internals.validity).toThrow();
23+
expect(() => internals.checkValidity()).toThrow();
24+
expect(() => internals.reportValidity()).toThrow();
25+
expect(() => internals.setValidity('')).toThrow();
26+
expect(() => internals.validationMessage).toThrow();
27+
expect(() => internals.labels).toThrow();
28+
29+
document.body.removeChild(form);
30+
};
31+
1132
describe.runIf(ENABLE_ELEMENT_INTERNALS_AND_FACE && typeof ElementInternals !== 'undefined')(
1233
'should throw an error when duplicate tag name used',
1334
() => {
@@ -38,30 +59,12 @@ describe.runIf(ENABLE_ELEMENT_INTERNALS_AND_FACE && typeof ElementInternals !==
3859
).not.toThrow();
3960
});
4061

41-
it('should throw an error when accessing form related properties on a non-form associated component', () => {
42-
const form = document.createElement('form');
43-
document.body.appendChild(form);
62+
it('should throw an error when accessing form related properties when formAssociated is false', () => {
63+
formAssociatedFalsyTest('x-form-associated-false', FormAssociatedFalse);
64+
});
4465

45-
const testElements = {
46-
'x-form-associated-false': FormAssociatedFalse,
47-
'x-not-form-associated': NotFormAssociated,
48-
};
49-
let elm;
50-
Object.entries(testElements).forEach(([tagName, ctor]) => {
51-
elm = createElement(`x-${tagName}`, { is: ctor });
52-
const { internals } = elm;
53-
form.appendChild(elm);
54-
expect(() => internals.form).toThrow();
55-
expect(() => internals.setFormValue('2019-03-15')).toThrow();
56-
expect(() => internals.willValidate).toThrow();
57-
expect(() => internals.validity).toThrow();
58-
expect(() => internals.checkValidity()).toThrow();
59-
expect(() => internals.reportValidity()).toThrow();
60-
expect(() => internals.setValidity('')).toThrow();
61-
expect(() => internals.validationMessage).toThrow();
62-
expect(() => internals.labels).toThrow();
63-
});
64-
document.body.removeChild(form);
66+
it('should throw an error when accessing form related properties when formAssociated is undefined', () => {
67+
formAssociatedFalsyTest('x-not-form-associated', NotFormAssociated);
6568
});
6669

6770
it('should be able to use internals to validate form associated component', () => {
@@ -116,7 +119,7 @@ describe.runIf(ENABLE_ELEMENT_INTERNALS_AND_FACE && typeof ElementInternals !==
116119
}
117120
);
118121

119-
it.runIf(typeof ElementInternals === 'undefined')(
122+
it.runIf(typeof ElementInternals !== 'undefined')(
120123
'disallows form association on older API versions',
121124
() => {
122125
const isFormAssociated = (elm) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:host(:state(--checked)) {
2+
color: rgb(255, 0, 0);
3+
}

packages/@lwc/integration-not-karma/test/component/LightningElement.attachInternals/elementInternals/sanity/index.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ describe.runIf(ENABLE_ELEMENT_INTERNALS_AND_FACE && typeof ElementInternals !==
2121
it('should be able to toggle states', () => {
2222
elm.toggleChecked();
2323
expect(elm.internals.states.has('--checked')).toBe(true);
24+
expect(getComputedStyle(elm).color).toBe('rgb(255, 0, 0)');
2425
elm.toggleChecked();
2526
expect(elm.internals.states.has('--checked')).toBe(false);
27+
expect(getComputedStyle(elm).color).toBe('rgb(0, 0, 0)');
2628
});
2729

2830
describe('accessibility', () => {

0 commit comments

Comments
 (0)