-
Notifications
You must be signed in to change notification settings - Fork 439
Expand file tree
/
Copy pathindex.spec.js
More file actions
54 lines (43 loc) · 1.94 KB
/
index.spec.js
File metadata and controls
54 lines (43 loc) · 1.94 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
import { createElement } from 'lwc';
import Parent from 'x/parent';
import Host from 'x/host';
import MultiTemplates from 'x/multiTemplates';
afterEach(() => {
window.__lwcResetGlobalStylesheets();
});
describe('shadow encapsulation', () => {
it('should not style children elements', () => {
const elm = createElement('x-parent', { is: Parent });
document.body.appendChild(elm);
const parentDiv = elm.shadowRoot.querySelector('div');
expect(window.getComputedStyle(parentDiv).marginLeft).toBe('10px');
const childDiv = elm.shadowRoot.querySelector('x-child').shadowRoot.querySelector('div');
expect(window.getComputedStyle(childDiv).marginLeft).toBe('0px');
});
it('should work with multiple templates', () => {
const elm = createElement('x-multi-template', { is: MultiTemplates });
document.body.appendChild(elm);
const div = elm.shadowRoot.querySelector('div');
expect(window.getComputedStyle(div).marginLeft).toBe('10px');
expect(window.getComputedStyle(div).marginRight).toBe('0px');
elm.toggleTemplate();
return Promise.resolve().then(() => {
const div = elm.shadowRoot.querySelector('div');
expect(window.getComputedStyle(div).marginLeft).toBe('0px');
expect(window.getComputedStyle(div).marginRight).toBe('10px');
});
});
});
describe(':host', () => {
it('should apply style to the host element', () => {
const elm = createElement('x-host', { is: Host });
document.body.appendChild(elm);
expect(window.getComputedStyle(elm).marginLeft).toBe('10px');
});
it('should apply style to the host element with the matching attributes', () => {
const elm = createElement('x-host', { is: Host });
elm.setAttribute('data-styled', true);
document.body.appendChild(elm);
expect(window.getComputedStyle(elm).marginLeft).toBe('20px');
});
});