-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathindex.spec.js
More file actions
127 lines (112 loc) · 5.57 KB
/
index.spec.js
File metadata and controls
127 lines (112 loc) · 5.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { createElement } from 'lwc';
import Light from 'x/light';
import Shadow from 'x/shadow';
import { jasmine } from '../../../helpers/jasmine.js';
import { nonStandardAriaProperties } from '../../../helpers/aria.js';
import {
attachReportingControlDispatcher,
detachReportingControlDispatcher,
} from '../../../helpers/reporting-control.js';
// This test only works if the ARIA reflection polyfill is loaded
describe.runIf(process.env.ENABLE_ARIA_REFLECTION_GLOBAL_POLYFILL)(
'non-standard ARIA properties',
() => {
let dispatcher;
beforeEach(() => {
dispatcher = jasmine.createSpy();
attachReportingControlDispatcher(dispatcher, ['NonStandardAriaReflection']);
});
afterEach(() => {
detachReportingControlDispatcher();
});
nonStandardAriaProperties.forEach((prop) => {
describe(prop, () => {
const scenarios = [
{ name: 'light', Ctor: Light, tagName: 'x-light' },
{ name: 'shadow', Ctor: Shadow, tagName: 'x-shadow' },
];
scenarios.forEach(({ name, Ctor, tagName }) => {
const inComponentWarning = `Error: [LWC warn]: Element <div> owned by <${tagName}> uses non-standard property "${prop}". This will be removed in a future version of LWC. See https://sfdc.co/deprecated-aria`;
const outsideComponentWarning = `Error: [LWC warn]: Element <span> uses non-standard property "${prop}". This will be removed in a future version of LWC. See https://sfdc.co/deprecated-aria`;
describe(name, () => {
let elm;
beforeEach(() => {
elm = createElement(tagName, { is: Ctor });
document.body.appendChild(elm);
});
it('LightningElement - inside component', () => {
expect(() => {
elm.setProp(prop, 'foo');
elm.getProp(prop);
}).not.toLogWarningDev();
expect(dispatcher).not.toHaveBeenCalled();
});
it('LightningElement - outside component', () => {
expect(() => {
elm[prop] = 'foo';
const unused = elm[prop];
return unused; // remove lint warning
}).not.toLogWarningDev();
expect(dispatcher).not.toHaveBeenCalled();
});
it('regular Element inside LightningElement', () => {
expect(() => {
elm.setPropOnElement(prop, 'foo');
elm.getPropOnElement(prop);
}).toLogWarningDev(inComponentWarning);
expect(dispatcher.calls.allArgs()).toEqual([
[
'NonStandardAriaReflection',
{
tagName,
propertyName: prop,
isSetter: true,
setValueType: 'string',
},
],
[
'NonStandardAriaReflection',
{
tagName,
propertyName: prop,
isSetter: false,
setValueType: undefined,
},
],
]);
});
it('regular Element outside LightningElement', () => {
const span = document.createElement('span');
document.body.appendChild(span);
expect(() => {
span[prop] = 'foo';
const unused = span[prop];
return unused; // remove lint warning
}).toLogWarningDev(outsideComponentWarning);
expect(dispatcher.calls.allArgs()).toEqual([
[
'NonStandardAriaReflection',
{
tagName: undefined,
propertyName: prop,
isSetter: true,
setValueType: 'string',
},
],
[
'NonStandardAriaReflection',
{
tagName: undefined,
propertyName: prop,
isSetter: false,
setValueType: undefined,
},
],
]);
});
});
});
});
});
}
);