-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathindex.spec.js
More file actions
49 lines (43 loc) · 1.7 KB
/
index.spec.js
File metadata and controls
49 lines (43 loc) · 1.7 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
import { createElement } from 'lwc';
import Inner from 'x/inner';
import Outer from 'x/outer';
import { jasmineSpyOn as spyOn } from '../../../helpers/jasmine.js';
import { extractDataIds } from '../../../helpers/utils.js';
beforeAll(() => {
customElements.define('omg-whatever', class extends HTMLElement {});
});
let consoleSpy;
beforeEach(() => {
consoleSpy = spyOn(console, 'warn');
});
for (const whatter of ['inner', 'outer']) {
// See W-16614337
it(`does not render ${whatter} HTML from attributes`, async () => {
const Whatter = whatter === 'inner' ? Inner : Outer;
const elm = createElement(`x-${whatter}`, { is: Whatter });
document.body.appendChild(elm);
await Promise.resolve();
const ids = Object.entries(extractDataIds(elm)).filter(
([id]) => !id.endsWith('.shadowRoot')
);
for (const [_id, node] of ids) {
expect(node.childNodes.length).toBe(1);
expect(node.firstChild.nodeType).toBe(Node.TEXT_NODE);
expect(node.firstChild.nodeValue).toBe('original');
}
if (process.env.NODE_ENV === 'production') {
expect(consoleSpy).not.toHaveBeenCalled();
} else {
const len = ids.filter(
([_id, elm]) => !elm.hasAttribute('data-expect-no-warning')
).length;
expect(consoleSpy).toHaveBeenCalledTimes(len);
const calls = consoleSpy.calls;
for (let i = 0; i < len; i += 1) {
expect(calls.argsFor(i)[0].message).toContain(
`Cannot set property "${whatter}HTML". Instead, use lwc:inner-html or lwc:dom-manual.`
);
}
}
});
}