-
Notifications
You must be signed in to change notification settings - Fork 209
/
Copy pathmy-element_test.ts
66 lines (57 loc) · 1.6 KB
/
my-element_test.ts
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
/**
* @license
* Copyright 2021 Google LLC
* SPDX-License-Identifier: BSD-3-Clause
*/
import {MyElement} from '../my-element.js';
// needed in order to guarantee MyElement gets defined.
import '../my-element.js';
import {fixture, html} from '@open-wc/testing';
const assert = chai.assert;
suite('my-element', () => {
test('is defined', () => {
const el = document.createElement('my-element');
assert.instanceOf(el, MyElement);
});
test('renders with default values', async () => {
const el = await fixture(html`<my-element></my-element>`);
assert.shadowDom.equal(
el,
`
<h1>Hello, World!</h1>
<button part="button">Click Count: 0</button>
<slot></slot>
`
);
});
test('renders with a set name', async () => {
const el = await fixture(html`<my-element name="Test"></my-element>`);
assert.shadowDom.equal(
el,
`
<h1>Hello, Test!</h1>
<button part="button">Click Count: 0</button>
<slot></slot>
`
);
});
test('handles a click', async () => {
const el = (await fixture(html`<my-element></my-element>`)) as MyElement;
const button = el.shadowRoot!.querySelector('button')!;
button.click();
await el.updateComplete;
assert.shadowDom.equal(
el,
`
<h1>Hello, World!</h1>
<button part="button">Click Count: 1</button>
<slot></slot>
`
);
});
test('styling applied', async () => {
const el = (await fixture(html`<my-element></my-element>`)) as MyElement;
await el.updateComplete;
assert.equal(getComputedStyle(el).paddingTop, '16px');
});
});