-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathindex.spec.js
More file actions
63 lines (49 loc) · 1.91 KB
/
index.spec.js
File metadata and controls
63 lines (49 loc) · 1.91 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
import { createElement } from 'lwc';
import Wrapper from 'x/wrapper';
import { ENABLE_THIS_DOT_HOST_ELEMENT } from '../../../helpers/utils.js';
function createWrapper() {
const elm = createElement('x-wrapper', { is: Wrapper });
document.body.appendChild(elm);
return elm;
}
it.runIf(ENABLE_THIS_DOT_HOST_ELEMENT)(
'should provide the root element for light rendering',
() => {
const elm = createWrapper();
const divElement = elm.getDivElement();
const lightElement = elm.getLightElement();
const hostElement = lightElement.getHostElement();
expect(hostElement).toBeTruthy();
expect(hostElement.tagName).toEqual('X-LIGHT');
expect(hostElement.dataset.name).toEqual('lightElement');
expect(hostElement).toEqual(lightElement);
expect(hostElement.parentElement).toEqual(divElement);
}
);
it.runIf(ENABLE_THIS_DOT_HOST_ELEMENT)(
'should provide the root element for shadow rendering',
() => {
const elm = createWrapper();
const divElement = elm.getDivElement();
const shadowElement = elm.getShadowElement();
const hostElement = shadowElement.getHostElement();
expect(hostElement).toBeTruthy();
expect(hostElement.tagName).toEqual('X-SHADOW');
expect(hostElement.dataset.name).toEqual('shadowElement');
expect(hostElement).toEqual(shadowElement);
expect(hostElement.parentElement).toEqual(divElement);
}
);
// this.hostElement unsupported
it.skipIf(ENABLE_THIS_DOT_HOST_ELEMENT)(
'this.hostElement unsupported in older API versions',
() => {
const elm = createWrapper();
const shadowElement = elm.getShadowElement();
let hostElement;
expect(() => {
hostElement = shadowElement.getHostElement();
}).toLogWarningDev(/Increase the API version to use it/);
expect(hostElement).toBeUndefined();
}
);